Tweet with Disaster(Kaggle NLP项目实战)
Tweet with Disaster(Kaggle NLP项目实战)
- 项目介绍(Real or Not? NLP with Disaster Tweets)
- EDA
- 数据预处理部分
- 1 导入数据
- 2 描述性分析
- 3 数据清洗
- 4 用词云进行可视化展示
- 导入Bert预训练模型
- 构造Bert模型输入
- 建立模型并训练
- 提交结果
项目介绍(Real or Not? NLP with Disaster Tweets)
项目kaggle链接:https://www.kaggle.com/c/nlp-getting-started/overview
在紧急情况下,Twitter已经成为一个重要的沟通渠道。智能手机的普及使人们能够实时宣布正在观察的紧急情况。正因为如此,越来越多的机构对程序化监控Twitter(即救灾组织和新闻机构)感兴趣。但是,人们并不总是清楚一个人的话是否真的在宣告一场灾难。比如下面的例子:
作者明确地使用了“燃烧”这个词,但它的意思是隐喻性的。这一点对人类来说是显而易见的,特别是在视觉辅助下。但对机器来说就不那么清楚了。
在这场竞争中,你面临着建立一个机器学习模型的挑战,该模型可以预测哪些Tweets是关于真正的灾难的,哪些Tweets不是。
EDA
数据预处理部分
1 导入数据
train = pd.read_csv('../input/nlp-getting-started/train.csv')
test = pd.read_csv('../input/nlp-getting-started/test.csv')
sample_submission = pd.read_csv('../input/nlp-getting-started/sample_submission.csv')# Print the shape of the training data
print('{} rows and {} cols in training dataset.'.format(train.shape[0], train.shape[1]))
print('{} rows and {} cols in training dataset.'.format(test.shape[0], test.shape[1]))# Inspecting the training data
train.head(10)
2 描述性分析
查看标签0和1的分布情况
# Frequency for taget variable
count_table = train.target.value_counts()
display(count_table)# Plot class distribution
plt.figure(figsize=(6,5))
plt.bar('False',count_table[0],label='False',width=0.6)
plt.bar('True', count_table[1],label='True',width=0.6)
plt.legend()
plt.ylabel('Count of examples')
plt.xlabel('Category')
plt.title('Class Distribution')
plt.ylim([0,4700])
plt.show()
每条推特长度的分布
# Plot the frequency of tweets length
bins = 150
plt.figure(figsize=(18,5))
plt.hist(train[train['target']==0]['length'], label= 'False',bins=bins,alpha=0.8)
plt.hist(train[train['target']==1]['length'], label= 'True', bins=bins,alpha=0.8)
plt.xlabel('Length of text (characters)')
plt.ylabel('Count')
plt.title('Frequency of tweets length')
plt.legend(loc='best')
plt.show()
两种推特的长度分布情况对比
# Frequency of tweets length in 2 classes
fg, (ax1, ax2)=plt.subplots(1,2,figsize=(14,5))
ax1.hist(train[train['target']==0]['length'],color='red')
ax1.set_title('Distribution of fake tweets')
ax1.set_xlabel('Tweets length (characters)')
ax1.set_ylabel('Count')
ax2.hist(train[train['target']==1]['length'],color='blue')
ax2.set_title('Distribution of true tweets')
ax2.set_xlabel('Tweets length (characters)')
ax2.set_ylabel('Count')
fg.suptitle('Characater in classes')
plt.show()
两种推特出现的词的数量分布
# Plot the distribution of count of words
words_true = train[train['target']==1]['text'].str.split().apply(len)
words_false = train[train['target']==0]['text'].str.split().apply(len)
plt.figure(figsize=(10,5))
plt.hist(words_false, label='False',alpha=0.8,bins=15)
plt.hist(words_true, label='True',alpha=0.6,bins=15)
plt.legend(loc='best')
plt.title('Count of words in tweets')
plt.xlabel('Count of words')
plt.ylabel('Count')
plt.show()
3 数据清洗
定义去除所有停用词,语气符号,html符号,表情符号的函数
# Define a function to remove URL
def remove_url(text):url = re.compile(r'https?://\S+|www\.\S+')return url.sub(r'',text)# Test function
test = 'Address of this kernel: https://www.kaggle.com/lilstarboy/kernel4d04fe5667/edit'
print(remove_url(test))# Define a function to remove html tag
def remove_html(text):html = re.compile(r'<.*?>')return html.sub(r'',text)# Test function
test = """<div>
<h1>Real or Fake</h1>
<p>Kaggle </p>
<a href="https://www.kaggle.com/c/nlp-getting-started">getting started</a>
</div>"""
print(remove_html(test))# Define a function to remove emojis
def remove_emoji(text):emoji_pattern = re.compile("["u"\U0001F600-\U0001F64F" # emoticonsu"\U0001F300-\U0001F5FF" # symbols & pictographsu"\U0001F680-\U0001F6FF" # transport & map symbolsu"\U0001F1E0-\U0001F1FF" # flags (iOS)u"\U00002702-\U000027B0"u"\U000024C2-\U0001F251""]+", flags=re.UNICODE)return emoji_pattern.sub(r'', text)remove_emoji("To test
Tweet with Disaster(Kaggle NLP项目实战)相关推荐
- 4个可以写进简历的京东 NLP 项目实战
01 京东AI项目实战课程安排 覆盖了从经典的机器学习.文本处理技术.序列模型.深度学习.预训练模型.知识图谱.图神经网络所有必要的技术. 项目一.京东健康智能分诊项目 第一周:文本处理与特征工程 | ...
- 【全网首发】京东AI三大NLP项目实战
<京东NLP企业项目实战训练营> 专注于培养行业TOP10%的NLP工程师 对课程有意向的同学 添加课程顾问小姐姐微信 报名.课程咨询 ???????????? 01 科学的实战安排 每一 ...
- 3个可以写进简历的京东AI NLP项目实战,走完这五步就是Top算法工程师
允中 发自 凹非寺 量子位 编辑 | 公众号 QbitAI 如何入门NLP?如何在实际案例中应用理论知识?如何成为行业Top10%的NLP工程师?如何规划AI工程师职业发展,一线AI公司有哪些项目? ...
- 3个可以写进简历的京东AI NLP项目实战
<京东NLP企业项目实战训练营> 专注于培养行业TOP10%的NLP工程师 对课程有意向的同学 添加课程顾问小姐姐微信 报名.课程咨询 ???????????? 01 科学的实战安排 每一 ...
- NLP项目实战—京东健康智能分诊文本分类项目
文章目录 引言 一.项目的描述与目标 二.项目框架 三.文本预处理与特征工程 1. 文本预处理 2. 特征工程 2.1 基于词向量的特征工程 2.2 基于人工定义的特征 四.三个任务 1.projec ...
- 【咕泡P5人工智能CV 技术NLP项目实战】
人工智能核心代码: public void string main(String agrs[]){//获取资料放在这里:链接:https://pan.baidu.com/s/1NZINLrOG748U ...
- 咕泡P5人工智能CV 技术NLP项目实战
人工智能核心代码 public void string main(String agrs[]){//获取课程链接:https://pan.baidu.com/s/1wqARPcq8IQtgqcxVy ...
- 【项目实战课】NLP入门第1课,人人免费可学,基于TextCNN的新闻文本分类实战...
欢迎大家来到我们的项目实战课,本期内容是<基于TextCNN的新闻文本分类实战>. 所谓项目课,就是以简单的原理回顾+详细的项目实战的模式,针对具体的某一个主题,进行代码级的实战讲解,可以 ...
- 4个可以写进简历的京东NLP项目:医疗分诊、营销文案生成、商品图谱、对话系统...
想成为NLP工程师,但是否因为没有实际项目经历而发愁?是否希望丰富简历中的项目经验,从而提高面试的通过率?是否想尝试有技术含量的项目,以后为进大厂而准备? 这就是我们实战训练营的初衷. 京东智联云联合 ...
最新文章
- 20行代码发一篇NeurIPS:梯度共享已经不安全了
- 腾讯面试官:如何停止一个正在运行的线程?我蒙了。。。
- Does the “LINQ to Objects” provider have built-in performance optimization?
- pandas内容像日期的数据如何变成真DataTime,并赋予时间类似的操作
- json文件中的双引号隐藏
- echarts指针进度条刻度调整_指针式流量开关
- POJ 1743 后缀数组
- 在后台增加一个查询条件
- bzoj 4832 [Lydsy1704月赛]抵制克苏恩 期望dp
- apache+php环境配置
- EAS BOS序时簿界面排序
- [生存志] 第20节 历代大事件概览 隋朝
- 在 Parallels Desktop 中,全屏模式使用 Win7,唤醒时黑屏
- 【java期末复习题】第4章 面向对象基础
- 最高法规定网络转载涉嫌侵权需担责 10月10日起施行
- CAP理论、AP架构、CP架构
- python-tkinter 官方文档
- FICO 里面的替代和校验 以及调试
- “速课小龙”项目冲刺2
- MS SQL SERVER 中merge join合并连接介绍(转)
热门文章
- 怎么看虚拟机服务器ip,虚拟主机的ip怎么看 查看主机ip的方法
- vue-cli 项目踩坑 npm install 时出错
- c语言程序设计P320,《C程序设计》作业内容
- Window10蓝牙无法连接的解决方案(已成功)
- 宁波计算机高考总分,盘点宁波的重高成绩单,惊人的升学数据让你想不到!
- 【物联网】21.物联网开发之先进传感 - RGB-D 传感器
- windows控制iPhone(不需要蓝牙)
- DMOZ编辑申请流程
- mysql怎么定位错误信息_如何快速定位MySQL 的错误日志(Error Log)?
- Java当中的IO流(中)