国内quora

Quora insincere question classification was a challenge organized by kaggle in the field of natural language processing. The main aim the challenge was to figure out the toxic and divisive content. It is binary classification problem where class 0 represented insincere question and class 1 otherwise. This blog would specifically deal with the data modelling part.

Quora真诚的问题分类是kaggle在自然语言处理领域组织的一项挑战。 挑战的主要目的是找出有毒和分裂性的内容。 这是二进制分类问题,其中类别0表示不诚实的问题,否则类别1。 该博客将专门处理数据建模部分。

预处理: (Preprocessing:)

In the first step we shall read the data using pandas. This code snippet would read the file into a pandas data frame.

第一步,我们将使用熊猫读取数据。 此代码段会将文件读入pandas数据框。

train=pd.read_csv(‘/kaggle/input/quora-insincere-questions-classification/train.csv’)test_df=pd.read_csv(‘/kaggle/input/quora-insincere-questions-classification/test.csv’)sub=pd.read_csv(‘/kaggle/input/quora-insincere-questions-classification/sample_submission.csv’)

We can know the shape of the data using the shape method.

我们可以使用shape方法知道数据的形状。

Initially we would try to divide the training dataset into 2 parts which are train and validation. To do so we can take help of sklearn. The following code snippet would help us achieve it.

最初,我们尝试将训练数据集分为训练和验证两部分。 为此,我们可以寻求sklearn的帮助。 以下代码段将帮助我们实现这一目标。

train_df,val_df=train_test_split(train,test_size=0.1)

In the first step we would try to fill the question that contain null values. To do so we can use the fillna method. The code snippet below would do the same.

第一步,我们将尝试填充包含空值的问题。 为此,我们可以使用fillna方法。 下面的代码段将执行相同的操作。

train_x=train_df['question_text'].fillna('__na__').valuesval_x=val_df['question_text'].fillna('__na__').valuestest_x=test_df['question_text'].fillna('__na__').values

Now it is the time to choose some of the important parameters. These are embedd_size,max_features and max_len. Here embedd_size represents the word vector size of each word we are going to represent, whereas max_features tells about the number of top frequency words which we shall consider. For example if we consider max_feature to be 50000 it would imply we shall take the 50000 most occurring words into consideration while converting them into vectors. Similarly max_len would imply starting from the beginning how many words we would. For example max_len 100 would mean we shall consider the only first 100 words. The following are the parameters chosen for the same.

现在是时候选择一些重要参数了。 这些是embedd_sizemax_featuresmax_len 。 这里的embedd_size表示我们将要表示的每个单词的单词向量大小,而max_features讲述了我们将要考虑的最高频率单词的数量。 例如,如果我们认为max_feature为50000,则意味着在将它们转换为向量时,应考虑50000个最常出现的单词。 类似地, max_len表示从头开始会有多少个单词。 例如max_len 100意味着我们将只考虑前100个字。 以下是为其选择的参数。

embedd_size=300max_features=50000max_len=100

Now consider the following code snippet.

现在考虑以下代码片段。

tokenizer=Tokenizer(num_words=max_features)tokenizer.fit_on_texts(list(train_df))train_x=tokenizer.texts_to_sequences(train_x)val_x=tokenizer.texts_to_sequences(val_x)test_x=tokenizer.texts_to_sequences(test_x)

Here we would take the most 50000 frequent words into account in the first line. The second line would convert each word into a unique number based on where it appears in the sentence. The text_to_sequence method in the third,fourth and fifth line would convert each sentence to the numbers. For example to convert “India won the match” we shall lookup the integer assigned to each word in the previous method fit_on_texts and change the sentence accordingly.

在第一行中,我们将考虑最多50000个常用词。 第二行将根据单词在句子中的位置将每个单词转换为唯一的数字。 第三,第四和第五行中的text_to_sequence方法会将每个句子转换为数字。 例如,要转换“ 印度赢得比赛 ”,我们将在先前的方法fit_on_texts中查找分配给每个单词的整数,并相应地更改句子。

train_x=pad_sequences(train_x,maxlen=max_len)val_x=pad_sequences(val_x,maxlen=max_len)test_x=pad_sequences(test_x,maxlen=max_len)

The above code snippet would ensure each sentence is converted to a particular length. This is done so that while giving this sequences in batches they would fit into a particular length. Hence it is required to pad or truncate some of the sequences.

上面的代码片段将确保将每个句子转换为特定的长度。 这样做是为了在批量分配此序列的同时,使其适合特定的长度。 因此,需要填充或截断某些序列。

造型: (Modelling:)

We shall take a bidirectional lstm in order to build this classification model. Before that we have to convert the text into numbers. We did the initial step of it in the last paragraph where each word was converted into unique integers. In the next step we shall convert the words into vectors using the keras embedding layer. We also have the option of using any pretrained word embedding but here we have chosen the embedding layer to learn the word embedding while training. Embedding layer assigns random vectors to the words initially but learns the word embedding for each as the training of the model goes on. The below snippet tells us about the whole modelling strategy.

我们将采用双向lstm来建立此分类模型。 在此之前,我们必须将文本转换为数字。 我们在最后一个段落中完成了它的第一步,其中每个单词都被转换为唯一的整数。 在下一步中,我们将使用keras嵌入层将单词转换为向量。 我们还可以选择使用任何预训练的单词嵌入,但是在这里,我们选择了嵌入层来在训练时学习单词嵌入。 嵌入层最初会为单词分配随机向量,但是随着模型的训练的进行,每个单词都将学习单词嵌入。 下面的代码段向我们介绍了整个建模策略。

inp=Input(shape=(max_len))x=Embedding(max_features,embedd_size)(inp)x=Bidirectional(LSTM(128,return_sequences=True))(x)x=GlobalMaxPool1D()(x)x=Dense(16,activation='relu')(x)x=Dropout(0.2)(x)x=Dense(1,activation='sigmoid')(x)model=Model(inputs=inp,outputs=x)model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])

After the embedding we shall use the bidirectional lstm. Here the parameter return sequence=True implies we would like to get the output of each hidden state. The deafult one is false which means we want the output of the final state only. Similarly the GlobalMaxPool1D implies that for each sentence vector we shall take the highest value only. Dropout layer is added to deal with the overfitting. The dense layer with the sigmoid activation function will output a value between 0 and 1. The compile method builds the model where no training has been performed yet.

嵌入之后,我们将使用双向lstm。 在这里,参数return sequence = True表示我们希望获取每个隐藏状态的输出。 默认值是假的,这意味着我们只需要最终状态的输出。 类似地, GlobalMaxPool1D意味着对于每个句子向量,我们将仅取最大值。 添加了辍学层以应对过度拟合。 具有S型激活函数的密集层将输出0到1之间的值。编译方法将在尚未进行训练的情况下构建模型。

In the compile method we had only defined the architecture and initialized it. Now we have to tune the parameters so as to get optimal model. To do so we pass the training data through the model. The fit method passes the data through model and computes the loss. Also based on the loss it does the backpropagation and tunes the parameters. The following code snippet does the same.

在编译方法中,我们仅定义了架构并对其进行了初始化。 现在我们必须调整参数以获得最佳模型。 为此,我们通过模型传递训练数据。 拟合方法通过模型传递数据并计算损失。 同样基于损耗,它进行反向传播并调整参数。 以下代码段执行相同的操作。

model.fit(train_x,train_out,batch_size=256,epochs=2,validation_data=(val_x,val_out))

After training for 2 epochs the model had achieved an accuracy of 93%. We can change the parameters and do hyperparameter tuning to get a better model.

在训练了2个时期后,该模型的准确率达到了93%。 我们可以更改参数并进行超参数调整以获得更好的模型。

The performance metric for this competition is F1 score. As the dataset is imbalanced.

这项比赛的表现指标是F1分数。 由于数据集不平衡。

To predict the model we can write

为了预测模型,我们可以写

pred_y=model.predict([test_x],batch_size=256)

The whole code can be found out at https://github.com/mohantyaditya/quora-insincere-classification/blob/master/quora%20insincere.ipynb

整个代码可以在https://github.com/mohantyaditya/quora-insincere-classification/blob/master/quora%20insincere.ipynb中找到

This was a pretty basic approach to the problem. We can try out with the pre trained embedding vectors to get better result.

这是解决该问题的非常基本的方法。 我们可以尝试使用预训练的嵌入向量以获得更好的结果。

Gain Access to Expert View — Subscribe to DDI Intel

获得访问专家视图的权限- 订阅DDI Intel

翻译自: https://medium.com/datadriveninvestor/approaching-the-quora-insincere-question-classification-problem-eb27b0ad3100

国内quora

http://www.taodudu.cc/news/show-4008102.html

相关文章:

  • quora
  • kaggle quora_我想以自己的方式使用网络,非常感谢Quora。
  • 支付宝免签 个人支付宝到银行卡
  • 支付宝扫码转账到银行卡/飞行模式
  • JS调起支付宝进行银行卡转账
  • 支付宝扫码转银行卡技术/隐藏部分卡号
  • 支付宝企业转账到个人账号(php源码,亲测)
  • 企业支付宝转账到个人银行卡(免费率 无限额)JAVA配置示例
  • 让天底下没有难接的支付|支付宝网银直连转账到银行卡对接故事续集 支付对接不是一个单纯技术问题 网银直连转账到银行卡开通方式揭晓
  • java支付宝转账到银行卡_Java 支付宝支付,退款,单笔转账到支付宝账户(单笔转账到支付宝账户)...
  • 企业支付宝转账到银行卡(免费率 无限额)PHP 演示示例
  • 「第五章」点击劫持(ClickJacking)
  • 如何从头开始创建可用于生产环境的Webpack 4配置
  • 1430. Crime and Punishment
  • 2019测试指南-web应用程序安全测试(二)指纹Web应用程序
  • Python3 - Dockerfile 最佳实践
  • Angular ng命令
  • web安全(3)-- ClickJacking(点击劫持)
  • ADF11g-041:禁止或允许其它网站添加ADF页面到iframe中
  • windows计算机操作题,计算机等级考试Windows操作题
  • 解锁!95%的Android程序员做性能优化时,存在的五大误区和两大疑点!
  • selenium 自动化测试 Chrome 大于 63 版本 不能重定向问题解决办法
  • 口语积累
  • 一级计算机网络应用题目操作,计算机一级考试excel操作题目
  • CSUOJ2257: Intergalactic Bidding
  • 网络安全-点击劫持(ClickJacking)的原理、攻击及防御
  • HACKTHEBOX——Starting Point Tier0
  • 在ADF应用中,能够通过 oracle.adf.view.rich.security.FRAME_BUSTING 参数来使用framebusting功能。
  • 绕过iframe busting
  • Busting Frame Busting: a Study of Clickjacking Vulnerabilities on Popular Sites

国内quora_处理Quora不真诚问题分类问题相关推荐

  1. 国内quora_电线之间:Quora联合创始人Charlie Cheever的访谈

    国内quora by Vivian Cromwell 通过维维安·克伦威尔(Vivian Cromwell) 电线之间:Quora联合创始人Charlie Cheever的访谈 (Between th ...

  2. R使用LSTM模型构建深度学习文本分类模型(Quora Insincere Questions Classification)

    R使用LSTM模型构建深度学习文本分类模型(Quora Insincere Questions Classification) Long Short Term 网络-- 一般就叫做 LSTM --是一 ...

  3. 计量科学大数据分级分类

    计量科学大数据分级分类 智峰, 田锋, 赵若凡 中国计量科学研究院国家计量科学数据中心,北京 100029 摘要:基于我国数据共享开放的发展趋势以及科研数据安全管理的相关政策,对我国计量行业数据分级分 ...

  4. 市面上有哪几种门_目前市面上木门的几种分类

    近日,小编收集整理了国内市面上木门的几种分类,与大家一同分享. 木门按用途分 如户门.卧室门.书房门.厨房门.浴卫门等,根据用途不同,规格.式样.性能有不同的要求.户门是出入之首,由于有大件物品出入, ...

  5. 景观生态学原理| 6 景观生态分类与评价

    6.1 景观生态分类 景观生态学是以人类与地表景观的相互作用为基本出发点,研究景观生态系统的结构.功能及变化规律,并进行有关评价.规划及管理的应用研究. 6.1.1 景观生态分类的发展 1 从土地分类 ...

  6. 非码农也能看懂的“机器学习”原理

    我们先来说个老生常谈的情景:某天你去买芒果,小贩摊了满满一车芒果,你一个个选好,拿给小贩称重,然后论斤付钱. 自然,你的目标是那些最甜最成熟的芒果,那怎么选呢?你想起来,啊外婆说过,明黄色的比淡黄色的 ...

  7. 大数据项目 --- 电商数仓(一)

    这个项目实在数据采集基础使用的,需要提前复习之前学的东西,否则的话就是很难继续学习.详见博客数据项目一 ---数据采集项目.大数据项目 --- 数据采集项目_YllasdW的博客-CSDN博客大数据第 ...

  8. 发表了一篇英文长文:语义信息G理论和逻辑贝叶斯推理for统计学习

    来源:人机与认知实验室 [本文是鲁晨光老师发表的一篇关于语义信息论和统计学习的论文写后感,发表在科学网上,特摘录推荐] 2019-8-21 01:04 |个人分类:信息的数学和哲学|系统分类:论文交流 ...

  9. python实习做什么工作-大一/大二学生Python实习的困惑?

    题主是一名非名校的CS本科学生,现在遇到了一些困惑,想请教一下热心的segmentfault网友.因为不是985/211名校,现在题主所在的这所学校我感觉学风非常不好,第一是整体水平太低,一学期结束了 ...

  10. 阿里云开发者大会:资源加应用酝酿云存储变局

    云存储的概念虽然是近两年提出的,但其实际应用早在10多年前便已随着基于互联网的 Email 系统而开始.最早由Hotmail 提出这一概念,如今 Gmail 成了这一领域的象征,其实质都是建立在云存储 ...

最新文章

  1. 一口气说出四种幂等性解决方案,面试官露出了姨母笑~
  2. 为Eclipse IDE for Java Developers安装插件,让其有Server和Project facets
  3. 汽车之家全系车型(包含历史停售车型)图片--参数分析
  4. Vbox linux虚拟机桥接(VM操作也类似)
  5. Linux 之三 静态库及动态库的编写和使用
  6. python 操作mysql数据库
  7. oracle存储过程插入自动编号,Oracle生成单据编号存储过程的实例代码
  8. python字符串转64位数字_python-将String转换为64位整数映射字符以自定义两位值映射...
  9. 数据库工作笔记010---Mysql中用SQL增加、删除字段,修改字段名、字段类型、注释,调整字段顺序总结
  10. Android 四种启动模式
  11. Java项目 学生信息管理系统 DAO设计模式
  12. 【Stanford Online】Engineering: Algorithms1 NO.4 The Master Method
  13. 港澳台手机号正则表达式,区号+手机
  14. php codesniffer 安装,Centos6.6安装PHP_CodeSniffer
  15. 任天堂 Wii 模拟器 Dolphin 已原生支持苹果 M1 Mac 电脑
  16. Flink 中的木桶效应:单个 subtask 卡死导致整个任务卡死
  17. 【LeetCode每日一题】810. 黑板异或游戏
  18. nginx代理常见问题
  19. firemonkey 点击任务栏图标不能最小化
  20. Wi-Fi Orb 洞悉一切

热门文章

  1. STM32F103C6T6初步学习
  2. Azkaban学习之路
  3. 汽车电子嵌入式相关知识
  4. 6款反垃圾邮件产品横向比较测试
  5. 谈谈机器学习(Machine Learning)大牛
  6. 服务器遇到DDOS攻击怎么办?
  7. 京东商城(mysql+python)
  8. window下isa防火墙详细安装
  9. 为什么固态硬盘比机械硬盘读取速度快?
  10. Unity Shader :实现漫反射与高光反射