PaddlePaddle飞桨《高层API助你快速上手深度学习》『深度学习7日打卡营』--自定义数据集OCEMOTION–中文情感分类

赛题背景

自从2017年具有划时代意义的Transformer模型问世以来,短短两年多的时间内,如雨后春笋般的出现了大量的预训练模型,比如:Bert,Albert,ELECTRA,RoBERta,T5,GPT3等等。然而之前的基准评测体系存在两个缺陷:评测强度不够,模型不通用。评测强度不够指的是选手只提交结果,不提交inference的代码。模型不通用指的是预训练模型不能保证在相同超参数情况下在所有任务上都获得比较好的性能。以上两点极大限制了预训练技术的应用和发展。如果我们能通过算法实现泛化能力强的中文预训练模型,这将提高下游业务的准确性,从而提升企业的核心竞争力,并为企业创造更多的价值。

为提供更好的比赛体验,我们同时为本赛题定制了系列工具教程,其中包括EasyTransfer、多任务baseline教程等。同时我们也将提供专属的视频直播学习通道,具体关注本赛题「参考资料」版块。

赛题描述及数据说明

本赛题精选了以下3个具有代表性的任务,要求选手提交的模型能够同时预测每个任务对应的标签:

数据说明

OCNLI:是第一个非翻译的、使用原生汉语的大型中文自然语言推理数据集;
OCEMOTION:是包含7个分类的细粒度情感性分析数据集;
TNEWS:来源于今日头条的新闻版块,共包含15个类别的新闻;

数据格式

任务1:OCNLI–中文原版自然语言推理

  • 0 一月份跟二月份肯定有一个月份有. 肯定有一个月份有 0
  • 1 一月份跟二月份肯定有一个月份有. 一月份有 1
  • 2 一月份跟二月份肯定有一个月份有. 一月二月都没有 2
  • 3 一点来钟时,张永红却来了 一点多钟,张永红来了 0
  • 4 不讲社会效果,信口开河,对任何事情都随意发议论,甚至信谣传谣,以讹传讹,那是会涣散队伍、贻误事业的 以讹传讹是有害的 0
  • (注:id 句子1 句子2 标签)

(注:标签集合:[蕴含,中性,不相关])

任务2:OCEMOTION–中文情感分类

  • 0 你知道多伦多附近有什么吗?哈哈有破布耶…真的书上写的你听哦…你家那块破布是世界上最大的破布,哈哈,骗你的啦它是说尼加拉瓜瀑布是世界上最大的瀑布啦…哈哈哈’'爸爸,她的头发耶!我们大扫除椅子都要翻上来我看到木头缝里有头发…一定是xx以前夹到的,你说是不是?[生病] sadness
  • 1 平安夜,圣诞节,都过了,我很难过,和妈妈吵了两天,以死相逼才终止战争,现在还处于冷战中。sadness
  • 2 我只是自私了一点,做自己想做的事情! sadness
  • 3 让感动的不仅仅是雨过天晴,还有泪水流下来的迷人眼神。happiness
  • 4 好日子 happiness

(注:id 句子 标签)

任务3:TNEWS–今日头条新闻标题分类

  • 0 上课时学生手机响个不停,老师一怒之下把手机摔了,家长拿发票让老师赔,大家怎么看待这种事? 108
  • 1 商赢环球股份有限公司关于延期回复上海证券交易所对公司2017年年度报告的事后审核问询函的公告 104
  • 2 通过中介公司买了二手房,首付都付了,现在卖家不想卖了。怎么处理? 106
  • 3 2018年去俄罗斯看世界杯得花多少钱? 112
  • 4 剃须刀的个性革新,雷明登天猫定制版新品首发 109
    (注:id 句子 标签)

评测方案

参赛选手仅可使用单模型,先求出每个任务的macro f1,然后在三个任务上取平均值,具体计算公式如下:

##计算公式:

名称 说明
TP(True Positive) 真阳性:预测为正,实际也为正
FP(False Positive) 假阳性:预测为正,实际为负
FN(False Negative) 假阴性:预测与负、实际为正
TN(True Negative) 真阴性:预测为负、实际也为负
P(Precision) 精确率 P = TP/(TP+FP)
R(Recall) 召回率 R = TP/(TP+FN)
F(f1-score) F-值 F = 2PR/(P+R)
macro f1
需要先计算出每一个类别的准召及其f1 score,然后通过求均值得到在整个样本上的f1 score。

https://tianchi.aliyun.com/competition/entrance/531841/information

实战

# 下载paddlenlp
!pip install --upgrade paddlenlp==2.0.0b4 
Looking in indexes: https://mirror.baidu.com/pypi/simple/
Requirement already up-to-date: paddlenlp==2.0.0b4 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (2.0.0b4)
Requirement already satisfied, skipping upgrade: h5py in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp==2.0.0b4) (2.9.0)
Requirement already satisfied, skipping upgrade: colorlog in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp==2.0.0b4) (4.1.0)
Requirement already satisfied, skipping upgrade: jieba in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp==2.0.0b4) (0.42.1)
Requirement already satisfied, skipping upgrade: visualdl in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp==2.0.0b4) (2.1.1)
Requirement already satisfied, skipping upgrade: seqeval in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp==2.0.0b4) (1.2.2)
Requirement already satisfied, skipping upgrade: colorama in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp==2.0.0b4) (0.4.4)
Requirement already satisfied, skipping upgrade: numpy>=1.7 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from h5py->paddlenlp==2.0.0b4) (1.16.4)
Requirement already satisfied, skipping upgrade: six in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from h5py->paddlenlp==2.0.0b4) (1.15.0)
Requirement already satisfied, skipping upgrade: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp==2.0.0b4) (3.14.0)
Requirement already satisfied, skipping upgrade: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp==2.0.0b4) (2.22.0)
Requirement already satisfied, skipping upgrade: flake8>=3.7.9 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp==2.0.0b4) (3.8.2)
Requirement already satisfied, skipping upgrade: Pillow>=7.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp==2.0.0b4) (7.1.2)
Requirement already satisfied, skipping upgrade: shellcheck-py in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp==2.0.0b4) (0.7.1.1)
Requirement already satisfied, skipping upgrade: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp==2.0.0b4) (1.0.0)
Requirement already satisfied, skipping upgrade: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp==2.0.0b4) (1.1.1)
Requirement already satisfied, skipping upgrade: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp==2.0.0b4) (0.8.53)
Requirement already satisfied, skipping upgrade: pre-commit in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp==2.0.0b4) (1.21.0)
Requirement already satisfied, skipping upgrade: scikit-learn>=0.21.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from seqeval->paddlenlp==2.0.0b4) (0.22.1)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl->paddlenlp==2.0.0b4) (2019.9.11)
Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl->paddlenlp==2.0.0b4) (2.8)
Requirement already satisfied, skipping upgrade: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl->paddlenlp==2.0.0b4) (1.25.6)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl->paddlenlp==2.0.0b4) (3.0.4)
Requirement already satisfied, skipping upgrade: pycodestyle<2.7.0,>=2.6.0a1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl->paddlenlp==2.0.0b4) (2.6.0)
Requirement already satisfied, skipping upgrade: mccabe<0.7.0,>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl->paddlenlp==2.0.0b4) (0.6.1)
Requirement already satisfied, skipping upgrade: pyflakes<2.3.0,>=2.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl->paddlenlp==2.0.0b4) (2.2.0)
Requirement already satisfied, skipping upgrade: importlib-metadata; python_version < "3.8" in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl->paddlenlp==2.0.0b4) (0.23)
Requirement already satisfied, skipping upgrade: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl->paddlenlp==2.0.0b4) (2019.3)
Requirement already satisfied, skipping upgrade: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl->paddlenlp==2.0.0b4) (2.8.0)
Requirement already satisfied, skipping upgrade: Jinja2>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl->paddlenlp==2.0.0b4) (2.10.1)
Requirement already satisfied, skipping upgrade: click>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl->paddlenlp==2.0.0b4) (7.0)
Requirement already satisfied, skipping upgrade: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl->paddlenlp==2.0.0b4) (0.16.0)
Requirement already satisfied, skipping upgrade: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl->paddlenlp==2.0.0b4) (1.1.0)
Requirement already satisfied, skipping upgrade: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl->paddlenlp==2.0.0b4) (0.18.0)
Requirement already satisfied, skipping upgrade: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl->paddlenlp==2.0.0b4) (3.9.9)
Requirement already satisfied, skipping upgrade: aspy.yaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl->paddlenlp==2.0.0b4) (1.3.0)
Requirement already satisfied, skipping upgrade: toml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl->paddlenlp==2.0.0b4) (0.10.0)
Requirement already satisfied, skipping upgrade: virtualenv>=15.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl->paddlenlp==2.0.0b4) (16.7.9)
Requirement already satisfied, skipping upgrade: identify>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl->paddlenlp==2.0.0b4) (1.4.10)
Requirement already satisfied, skipping upgrade: nodeenv>=0.11.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl->paddlenlp==2.0.0b4) (1.3.4)
Requirement already satisfied, skipping upgrade: pyyaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl->paddlenlp==2.0.0b4) (5.1.2)
Requirement already satisfied, skipping upgrade: cfgv>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl->paddlenlp==2.0.0b4) (2.0.1)
Requirement already satisfied, skipping upgrade: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn>=0.21.3->seqeval->paddlenlp==2.0.0b4) (0.14.1)
Requirement already satisfied, skipping upgrade: scipy>=0.17.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn>=0.21.3->seqeval->paddlenlp==2.0.0b4) (1.3.0)
Requirement already satisfied, skipping upgrade: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata; python_version < "3.8"->flake8>=3.7.9->visualdl->paddlenlp==2.0.0b4) (0.6.0)
Requirement already satisfied, skipping upgrade: MarkupSafe>=0.23 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.5->Flask-Babel>=1.0.0->visualdl->paddlenlp==2.0.0b4) (1.1.1)
Requirement already satisfied, skipping upgrade: more-itertools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from zipp>=0.5->importlib-metadata; python_version < "3.8"->flake8>=3.7.9->visualdl->paddlenlp==2.0.0b4) (7.2.0)
# 解压数据
%cd ~
!unzip data/data66630/NLP中文预训练模型泛化能力挑战赛.zip -d dataset
/home/aistudio
Archive:  data/data66630/NLP中文预训练模型泛化能力挑战赛.zip
  inflating: dataset/OCEMOTION_a.csv  
  inflating: dataset/OCEMOTION_train1128.csv  
  inflating: dataset/OCNLI_a.csv     
  inflating: dataset/OCNLI_train1128.csv  
  inflating: dataset/TNEWS_a.csv     
  inflating: dataset/TNEWS_train1128.csv  
import paddle
import paddlenlp

print(paddle.__version__, paddlenlp.__version__)

2.0.0 2.0.0b4

数据集切分

import os
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
def break_data(target, rate=0.2):
    origin_dataset = pd.read_csv("dataset/OCEMOTION_train1128.csv", delimiter="\t", header=None)  # 加入参数
    train_data, test_data = train_test_split(origin_dataset, test_size=rate)
    train_data,eval_data=train_test_split(train_data, test_size=rate)
    train_filename = os.path.join(target, 'train.txt')
    test_filename = os.path.join(target, 'test.txt')
    eval_filename = os.path.join(target, 'eval.txt')

    train_data.to_csv(train_filename, index=False, sep="\t", header=None)
    test_data.to_csv(test_filename, index=False, sep="\t", header=None)
    eval_data.to_csv(eval_filename, index=False, sep="\t", header=None)


if __name__ == '__main__':
    break_data(target='dataset', rate=0.2)
%cd ~/dataset/
/home/aistudio/dataset
label_map={
     "sadness":'0', "happiness":'1',"disgust":'2',"like":'3',"anger":'4',"surprise":'5',"fear":'6'}
import pandas as pd

def modify_data(target='.'):
    for name in ['train','test','eval']:
        source_file=os.path.join(target, name + '.txt')
        target_file=os.path.join(target, name + '.csv')
        data=pd.read_csv(source_file, delimiter="\t", header=None) 
        new_data=data[[1,2]]
        new_data.replace(label_map, inplace=True)
        new_data.to_csv(target_file, index=False, sep="\t", header=None)
        new_data=None
        data=None




if __name__ == '__main__':
    modify_data()
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pandas/core/frame.py:3798: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  method=method)
!head train.csv
以前的一位同事和女朋友在一起了很多年,马上就结婚了!今天看到他上传的结婚照,新娘竟然不是她,而是公司的另一同事......现在的情感到底都是闹那样???	5
那种感觉真美好如果你也对我那样就好了♥	3
在元旦放假的前一天我们进行考试,远旦放假回来的头一天我们又要考试...每天考考考,做为高三的学生我们容易嘛。『明天的考试只能尽力了』	0
其实不幸福,只是一比较就幸福了	1
觉得自己太聪明也就会变傻噜。	1
我非常讨厌加工作q但是不知道怎么拒绝,毕竟已经拒绝了微信	4
非诚勿扰告诉我们:身为一个中国女性,无论你再怎么学历牛x、工作拼命、容颜姣好,到了年龄嫁不出去,就不得不穿的像驻马店洗浴中心的工作人员一样,站成一排会见各种奇葩,然后在三分钟的速食相亲之后假装找到真爱。。。	2
为了塞spn的con还有早餐会删掉了一堆喜欢的剧集存档......波吉亚家族嘤嘤嘤嘤嘤......【看起了蓝光碟【够。	0
希望每天	1
要是我没记错的话,我钱包里好像多了两百[挖鼻屎]	5
!head test.csv
【旅游】美食:滇南地区建水的蕈芽、石屏的豆腐、蒙自的过桥米线。滇东北地区菜豆花、连渣搞、酸辣鸡等。滇西地区的大理沙锅鱼、酸辣鱼。丽江粑粑、八大碗。弥渡的卷蹄、风吹肝、腾冲的大救驾,各种凉拌野菜、松尖等。关注【游遍云南】公众微信,让您畅游云南,游遍云南公众微信号:y4000119001	1
想哭,	0
自己打的赌,赌的很大,不知道自己到底战绩怎样	0
4...这都不是偶然的事情,这是他明白这个事实真相,对生死看得很淡薄,知道要认真努力修行,所以死了之后,自己可以作主,自己可以选择到哪一道去。如果在临终时,一慌一乱,你对身体很留恋,对家亲眷属很留恋,那你往往就到三途去了!	6
干了这碗香菜我们是好朋友	1
韩国沉船遇难者'不愿分离'。一男生一女生害怕被水冲开分离紧捆绑在一起。[蜡烛][蜡烛][蜡烛]	1
那一年,苍井空还是处女,冠希还没有相机,李刚还没有儿子,菊花只是一种花,企鹅不是qq,2b我只知道是铅笔,买方便面还有调料,杯具只是用来刷牙,楼房是用来住的,黄瓜香蕉只是用来吃的,教授还不是叫兽,太阳还不叫日,领导不会写日记,鸭梨还没有这么大,肚子大了也知道是谁的我们还相信真情	1
小孩子会说谎,大孩子也会说谎,不过,美名其曰为“借口”,不努力,是因为没了目标,没了动力,习惯了堕落。。。	3
特困户的春天[拜拜]	1
找院长写推荐信之前把自我介绍想过很多遍,结果院长大人没有赴约;从早到晚在实验室忙碌只为了按时完成实验,结果教授将实验计划改变;纠结了好久今天终于鼓起勇气再加一次某人的微信,结果我貌似在黑名单里面......总以为解决了自己就解决了一切,但是没想到,事情总是有想不懂到的一面。	2
!head eval.csv
我告诉自己,要独立,要坚强,要勇敢,要活的漂亮,要让自己永远善良。	1
人的自信无缘就是来自二种情况一是有钱二是有本事你们说是吗?????????????	2
18.粗一我们是一个学校同宿舍你是我上铺哟老是欺负我!!!是同胞啊嘿嘿内涵你懂。是品味不错的妹子还是大富逼!!总是给我礼物小惊喜啊啥的比如好吃的还有轻松熊本子还有美国带回来的杂志,射射你噜。看样子大学你是要粗国念噜别忘了我啊有空寄明信片啊好吃的好玩的给我不谢!!有缘再见咯高中加油!!	3
这说什么好呢?学校终于给放假啦!!开心死我了!!哈哈	1
愿沐儿天天开心~	1
如果你给不了幸福她,就请你不要伤害她,这样对彼此的伤害会更大。	0
前排的电车单车都倒地,纠结很久还是决定一辆辆扶起。一电车突然亮灯,一男生走过来,我赶紧解释不是我弄的!男生我知道。心里有点好奇,这哥们太善解人意了,抬头一看那男生,原来刚才走在后面的人不就是他么。倒车的时候,路太窄,我不小心又撞到后面的车,那哥们看了我一眼,继续心疼他的车...	0
我说那样的话真该死。	0
害怕失败,容易恐惧,逃避竞争。	0
当发现一些不该发现的事的时候,她就会下楼,说,还是睡觉吧。	5
train_data=pd.read_csv("train.csv", delimiter="\t", header=None) 
print("train_data length: ",train_data.size)
test_data=pd.read_csv("test.csv", delimiter="\t", header=None)  
print("test_data length: ",test_data.size)
eval_data=pd.read_csv("eval.csv", delimiter="\t", header=None)  
print("eval_data length: ",eval_data.size)
df1=train_data[1].value_counts()
print(df1)

train_data length:  45196
test_data length:  14126
eval_data length:  11300
0    7887
1    5776
2    2750
3    2642
4    2640
5     544
6     359
Name: 1, dtype: int64
%cd ~/dataset/
/home/aistudio/dataset
print(label_map)
{'sadness': '0', 'happiness': '1', 'disgust': '2', 'like': '3', 'anger': '4', 'surprise': '5', 'fear': '6'}
class SelfDefinedDataset(paddle.io.Dataset):
    def __init__(self, data):
        super(SelfDefinedDataset, self).__init__()
        self.data = data

    def __getitem__(self, idx):
        return self.data[idx]

    def __len__(self):
        return len(self.data)
        
    def get_labels(self):
        return ['0','1','2','3','4','5','6']



def txt_to_list(file_name):
    res_list = []
    for line in open(file_name):
        res_list.append(line.strip().split('\t'))
    return res_list

trainlst = txt_to_list('train.csv')
devlst = txt_to_list('eval.csv')
testlst = txt_to_list('test.csv')

# 通过get_datasets()函数,将list数据转换为dataset。
# get_datasets()可接收[list]参数,或[str]参数,根据自定义数据集的写法自由选择。
# train_ds, dev_ds, test_ds = ppnlp.datasets.ChnSentiCorp.get_datasets(['train', 'dev', 'test'])
train_ds, dev_ds, test_ds = SelfDefinedDataset.get_datasets([trainlst, devlst, testlst])


label_list = train_ds.get_labels()
print(label_list)

for i in range(10):
    print (train_ds[i])
['0', '1', '2', '3', '4', '5', '6']
['以前的一位同事和女朋友在一起了很多年,马上就结婚了!今天看到他上传的结婚照,新娘竟然不是她,而是公司的另一同事......现在的情感到底都是闹那样???', '5']
['那种感觉真美好如果你也对我那样就好了♥', '3']
['在元旦放假的前一天我们进行考试,远旦放假回来的头一天我们又要考试...每天考考考,做为高三的学生我们容易嘛。『明天的考试只能尽力了』', '0']
['其实不幸福,只是一比较就幸福了', '1']
['觉得自己太聪明也就会变傻噜。', '1']
['我非常讨厌加工作q但是不知道怎么拒绝,毕竟已经拒绝了微信', '4']
['非诚勿扰告诉我们:身为一个中国女性,无论你再怎么学历牛x、工作拼命、容颜姣好,到了年龄嫁不出去,就不得不穿的像驻马店洗浴中心的工作人员一样,站成一排会见各种奇葩,然后在三分钟的速食相亲之后假装找到真爱。。。', '2']
['为了塞spn的con还有早餐会删掉了一堆喜欢的剧集存档......波吉亚家族嘤嘤嘤嘤嘤......【看起了蓝光碟【够。', '0']
['希望每天', '1']
['要是我没记错的话,我钱包里好像多了两百[挖鼻屎]', '5']

数据处理

为了将原始数据处理成模型可以读入的格式,本项目将对数据作以下处理:

  • 首先使用jieba切词,之后将jieba切完后的单词映射词表中单词id。

PaddlePaddle飞桨《高层API助你快速上手深度学习》『深度学习7日打卡营』--自定义数据集OCEMOTION–中文情感分类_第1张图片

  • 使用paddle.io.DataLoader接口多线程异步加载数据。

其中用到了PaddleNLP中关于数据处理的API。PaddleNLP提供了许多关于NLP任务中构建有效的数据pipeline的常用API

API 简介
paddlenlp.data.Stack 堆叠N个具有相同shape的输入数据来构建一个batch,它的输入必须具有相同的shape,输出便是这些输入的堆叠组成的batch数据。
paddlenlp.data.Pad 堆叠N个输入数据来构建一个batch,每个输入数据将会被padding到N个输入数据中最大的长度
paddlenlp.data.Tuple 将多个组batch的函数包装在一起

更多数据处理操作详见: https://github.com/PaddlePaddle/PaddleNLP/blob/develop/docs/data.md

# 下载词汇表文件word_dict.txt,用于构造词-id映射关系。

from utils import load_vocab, convert_example
# !wget https://paddlenlp.bj.bcebos.com/data/senta_word_dict.txt

# 加载词表
vocab = load_vocab('./senta_word_dict.txt')

for k, v in vocab.items():
    print(k, v)
    break
[PAD] 0
import numpy as np
from functools import partial

import paddle.nn as nn
import paddle.nn.functional as F
import paddlenlp as ppnlp
from paddlenlp.data import Pad, Stack, Tuple
from paddlenlp.datasets import MapDatasetWrapper

from utils import load_vocab, convert_example
# Reads data and generates mini-batches.
def create_dataloader(dataset,
                      trans_function=None,
                      mode='train',
                      batch_size=1,
                      pad_token_id=0,
                      batchify_fn=None):
    if trans_function:
        dataset = dataset.apply(trans_function, lazy=True)

    # return_list 数据是否以list形式返回
    # collate_fn  指定如何将样本列表组合为mini-batch数据。传给它参数需要是一个callable对象,需要实现对组建的batch的处理逻辑,并返回每个batch的数据。在这里传入的是`prepare_input`函数,对产生的数据进行pad操作,并返回实际长度等。
    dataloader = paddle.io.DataLoader(
        dataset,
        return_list=True,
        batch_size=batch_size,
        collate_fn=batchify_fn)
        
    return dataloader

# python中的偏函数partial,把一个函数的某些参数固定住(也就是设置默认值),返回一个新的函数,调用这个新函数会更简单。
trans_function = partial(
    convert_example,
    vocab=vocab,
    unk_token_id=vocab.get('[UNK]', 1),
    is_test=False)

# 将读入的数据batch化处理,便于模型batch化运算。
# batch中的每个句子将会padding到这个batch中的文本最大长度batch_max_seq_len。
# 当文本长度大于batch_max_seq时,将会截断到batch_max_seq_len;当文本长度小于batch_max_seq时,将会padding补齐到batch_max_seq_len.
batchify_fn = lambda samples, fn=Tuple(
    Pad(axis=0, pad_val=vocab['[PAD]']),  # input_ids
    Stack(dtype="int64"),  # seq len
    Stack(dtype="int64")  # label
): [data for data in fn(samples)]


train_loader = create_dataloader(
    train_ds,
    trans_function=trans_function,
    batch_size=128,
    mode='train',
    batchify_fn=batchify_fn)
dev_loader = create_dataloader(
    dev_ds,
    trans_function=trans_function,
    batch_size=128,
    mode='validation',
    batchify_fn=batchify_fn)
test_loader = create_dataloader(
    test_ds,
    trans_function=trans_function,
    batch_size=128,
    mode='test',
    batchify_fn=batchify_fn)
class LSTMModel(nn.Layer):
    def __init__(self,
                 vocab_size,
                 num_classes,
                 emb_dim=128,
                 padding_idx=0,
                 lstm_hidden_size=198,
                 direction='forward',
                 lstm_layers=1,
                 dropout_rate=0,
                 pooling_type=None,
                 fc_hidden_size=96):
        super().__init__()

        # 首先将输入word id 查表后映射成 word embedding
        self.embedder = nn.Embedding(
            num_embeddings=vocab_size,
            embedding_dim=emb_dim,
            padding_idx=padding_idx)

        # 将word embedding经过LSTMEncoder变换到文本语义表征空间中
        self.lstm_encoder = ppnlp.seq2vec.LSTMEncoder(
            emb_dim,
            lstm_hidden_size,
            num_layers=lstm_layers,
            direction=direction,
            dropout=dropout_rate,
            pooling_type=pooling_type)

        # LSTMEncoder.get_output_dim()方法可以获取经过encoder之后的文本表示hidden_size
        self.fc = nn.Linear(self.lstm_encoder.get_output_dim(), fc_hidden_size)

        # 最后的分类器
        self.output_layer = nn.Linear(fc_hidden_size, num_classes)

    def forward(self, text, seq_len):
        # text shape: (batch_size, num_tokens)
        # print('input :', text.shape)
        
        # Shape: (batch_size, num_tokens, embedding_dim)
        embedded_text = self.embedder(text)
        # print('after word-embeding:', embedded_text.shape)

        # Shape: (batch_size, num_tokens, num_directions*lstm_hidden_size)
        # num_directions = 2 if direction is 'bidirectional' else 1
        text_repr = self.lstm_encoder(embedded_text, sequence_length=seq_len)
        # print('after lstm:', text_repr.shape)


        # Shape: (batch_size, fc_hidden_size)
        fc_out = paddle.tanh(self.fc(text_repr))
        # print('after Linear classifier:', fc_out.shape)

        # Shape: (batch_size, num_classes)
        logits = self.output_layer(fc_out)
        # print('output:', logits.shape)
        
        # probs 分类概率值
        probs = F.softmax(logits, axis=-1)
        # print('output probability:', probs.shape)
        return probs

model= LSTMModel(
        len(vocab),
        len(label_list),
        direction='bidirectional',
        padding_idx=vocab['[PAD]'])
model = paddle.Model(model)
optimizer = paddle.optimizer.Adam(
        parameters=model.parameters(), learning_rate=5e-5)

loss = paddle.nn.CrossEntropyLoss()
metric = paddle.metric.Accuracy()

model.prepare(optimizer, loss, metric)
# 设置visualdl路径
log_dir = './visualdl'
callback = paddle.callbacks.VisualDL(log_dir=log_dir)
model.fit(train_loader, dev_loader, epochs=20, save_dir='./checkpoints', save_freq=5, callbacks=callback)
The loss value printed in the log is the current step, and the metric is the average value of previous step.
Epoch 1/20
step  10/177 - loss: 1.7287 - acc: 0.4359 - 78ms/step
step  20/177 - loss: 1.7128 - acc: 0.4437 - 69ms/step
step  30/177 - loss: 1.7236 - acc: 0.4471 - 65ms/step
step  40/177 - loss: 1.6971 - acc: 0.4467 - 64ms/step
step  50/177 - loss: 1.7753 - acc: 0.4523 - 63ms/step
step  60/177 - loss: 1.7195 - acc: 0.4542 - 62ms/step
step  70/177 - loss: 1.7171 - acc: 0.4548 - 62ms/step
step  80/177 - loss: 1.7066 - acc: 0.4578 - 62ms/step
step  90/177 - loss: 1.6546 - acc: 0.4621 - 62ms/step
step 100/177 - loss: 1.6884 - acc: 0.4655 - 63ms/step
step 110/177 - loss: 1.6837 - acc: 0.4679 - 63ms/step
step 120/177 - loss: 1.7230 - acc: 0.4706 - 63ms/step
step 130/177 - loss: 1.7261 - acc: 0.4719 - 64ms/step
step 140/177 - loss: 1.6388 - acc: 0.4733 - 63ms/step
step 150/177 - loss: 1.6855 - acc: 0.4751 - 63ms/step
step 160/177 - loss: 1.7011 - acc: 0.4745 - 62ms/step
step 170/177 - loss: 1.6465 - acc: 0.4761 - 62ms/step
step 177/177 - loss: 1.6205 - acc: 0.4788 - 61ms/step
save checkpoint at /home/aistudio/dataset/checkpoints/0
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.7202 - acc: 0.4742 - 59ms/step
step 20/45 - loss: 1.6818 - acc: 0.4734 - 50ms/step
step 30/45 - loss: 1.7037 - acc: 0.4719 - 47ms/step
step 40/45 - loss: 1.7151 - acc: 0.4730 - 45ms/step
step 45/45 - loss: 1.7573 - acc: 0.4759 - 41ms/step
Eval samples: 5650
Epoch 2/20
step  10/177 - loss: 1.6778 - acc: 0.4898 - 71ms/step
step  20/177 - loss: 1.6761 - acc: 0.4973 - 62ms/step
step  30/177 - loss: 1.6891 - acc: 0.4984 - 59ms/step
step  40/177 - loss: 1.6555 - acc: 0.4949 - 58ms/step
step  50/177 - loss: 1.7530 - acc: 0.4994 - 57ms/step
step  60/177 - loss: 1.7246 - acc: 0.4990 - 56ms/step
step  70/177 - loss: 1.6744 - acc: 0.5006 - 55ms/step
step  80/177 - loss: 1.6673 - acc: 0.5026 - 55ms/step
step  90/177 - loss: 1.6177 - acc: 0.5062 - 55ms/step
step 100/177 - loss: 1.6635 - acc: 0.5077 - 55ms/step
step 110/177 - loss: 1.6533 - acc: 0.5093 - 55ms/step
step 120/177 - loss: 1.6917 - acc: 0.5114 - 55ms/step
step 130/177 - loss: 1.6860 - acc: 0.5123 - 55ms/step
step 140/177 - loss: 1.5986 - acc: 0.5134 - 54ms/step
step 150/177 - loss: 1.6517 - acc: 0.5150 - 54ms/step
step 160/177 - loss: 1.6736 - acc: 0.5137 - 55ms/step
step 170/177 - loss: 1.6075 - acc: 0.5146 - 55ms/step
step 177/177 - loss: 1.6012 - acc: 0.5162 - 54ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.7132 - acc: 0.4906 - 61ms/step
step 20/45 - loss: 1.6558 - acc: 0.4879 - 51ms/step
step 30/45 - loss: 1.6922 - acc: 0.4859 - 48ms/step
step 40/45 - loss: 1.6910 - acc: 0.4859 - 45ms/step
step 45/45 - loss: 1.7414 - acc: 0.4874 - 41ms/step
Eval samples: 5650
Epoch 3/20
step  10/177 - loss: 1.6329 - acc: 0.5180 - 70ms/step
step  20/177 - loss: 1.6654 - acc: 0.5219 - 62ms/step
step  30/177 - loss: 1.6712 - acc: 0.5190 - 59ms/step
step  40/177 - loss: 1.6381 - acc: 0.5131 - 58ms/step
step  50/177 - loss: 1.7364 - acc: 0.5172 - 57ms/step
step  60/177 - loss: 1.6894 - acc: 0.5176 - 56ms/step
step  70/177 - loss: 1.6463 - acc: 0.5204 - 56ms/step
step  80/177 - loss: 1.6527 - acc: 0.5221 - 56ms/step
step  90/177 - loss: 1.5840 - acc: 0.5247 - 55ms/step
step 100/177 - loss: 1.6494 - acc: 0.5264 - 55ms/step
step 110/177 - loss: 1.6251 - acc: 0.5286 - 55ms/step
step 120/177 - loss: 1.6780 - acc: 0.5309 - 55ms/step
step 130/177 - loss: 1.6606 - acc: 0.5322 - 55ms/step
step 140/177 - loss: 1.5719 - acc: 0.5332 - 56ms/step
step 150/177 - loss: 1.6287 - acc: 0.5345 - 56ms/step
step 160/177 - loss: 1.6527 - acc: 0.5333 - 56ms/step
step 170/177 - loss: 1.5689 - acc: 0.5339 - 56ms/step
step 177/177 - loss: 1.5884 - acc: 0.5357 - 55ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6962 - acc: 0.4938 - 56ms/step
step 20/45 - loss: 1.6547 - acc: 0.4891 - 47ms/step
step 30/45 - loss: 1.6745 - acc: 0.4878 - 44ms/step
step 40/45 - loss: 1.6803 - acc: 0.4891 - 42ms/step
step 45/45 - loss: 1.7351 - acc: 0.4903 - 38ms/step
Eval samples: 5650
Epoch 4/20
step  10/177 - loss: 1.6304 - acc: 0.5359 - 72ms/step
step  20/177 - loss: 1.6395 - acc: 0.5414 - 64ms/step
step  30/177 - loss: 1.6470 - acc: 0.5414 - 61ms/step
step  40/177 - loss: 1.6467 - acc: 0.5338 - 60ms/step
step  50/177 - loss: 1.7319 - acc: 0.5337 - 59ms/step
step  60/177 - loss: 1.6845 - acc: 0.5328 - 58ms/step
step  70/177 - loss: 1.6379 - acc: 0.5354 - 58ms/step
step  80/177 - loss: 1.6338 - acc: 0.5364 - 58ms/step
step  90/177 - loss: 1.5668 - acc: 0.5389 - 59ms/step
step 100/177 - loss: 1.6374 - acc: 0.5405 - 59ms/step
step 110/177 - loss: 1.6243 - acc: 0.5422 - 59ms/step
step 120/177 - loss: 1.6647 - acc: 0.5437 - 58ms/step
step 130/177 - loss: 1.6424 - acc: 0.5445 - 58ms/step
step 140/177 - loss: 1.5531 - acc: 0.5456 - 58ms/step
step 150/177 - loss: 1.6118 - acc: 0.5466 - 58ms/step
step 160/177 - loss: 1.6469 - acc: 0.5451 - 58ms/step
step 170/177 - loss: 1.5548 - acc: 0.5458 - 57ms/step
step 177/177 - loss: 1.5783 - acc: 0.5476 - 56ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6974 - acc: 0.5000 - 53ms/step
step 20/45 - loss: 1.6367 - acc: 0.4977 - 44ms/step
step 30/45 - loss: 1.6816 - acc: 0.4914 - 42ms/step
step 40/45 - loss: 1.6775 - acc: 0.4898 - 40ms/step
step 45/45 - loss: 1.7240 - acc: 0.4913 - 36ms/step
Eval samples: 5650
Epoch 5/20
step  10/177 - loss: 1.6274 - acc: 0.5508 - 70ms/step
step  20/177 - loss: 1.6300 - acc: 0.5543 - 63ms/step
step  30/177 - loss: 1.6357 - acc: 0.5526 - 60ms/step
step  40/177 - loss: 1.6132 - acc: 0.5455 - 59ms/step
step  50/177 - loss: 1.7024 - acc: 0.5455 - 58ms/step
step  60/177 - loss: 1.6555 - acc: 0.5451 - 57ms/step
step  70/177 - loss: 1.6265 - acc: 0.5459 - 57ms/step
step  80/177 - loss: 1.6358 - acc: 0.5451 - 56ms/step
step  90/177 - loss: 1.5599 - acc: 0.5468 - 56ms/step
step 100/177 - loss: 1.6286 - acc: 0.5481 - 55ms/step
step 110/177 - loss: 1.6047 - acc: 0.5497 - 55ms/step
step 120/177 - loss: 1.6503 - acc: 0.5516 - 55ms/step
step 130/177 - loss: 1.6327 - acc: 0.5523 - 55ms/step
step 140/177 - loss: 1.5396 - acc: 0.5532 - 54ms/step
step 150/177 - loss: 1.5986 - acc: 0.5539 - 54ms/step
step 160/177 - loss: 1.6358 - acc: 0.5522 - 54ms/step
step 170/177 - loss: 1.5499 - acc: 0.5524 - 55ms/step
step 177/177 - loss: 1.5758 - acc: 0.5538 - 54ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6860 - acc: 0.5000 - 59ms/step
step 20/45 - loss: 1.6504 - acc: 0.4965 - 49ms/step
step 30/45 - loss: 1.6756 - acc: 0.4930 - 47ms/step
step 40/45 - loss: 1.6687 - acc: 0.4930 - 45ms/step
step 45/45 - loss: 1.7152 - acc: 0.4954 - 41ms/step
Eval samples: 5650
Epoch 6/20
step  10/177 - loss: 1.6168 - acc: 0.5563 - 73ms/step
step  20/177 - loss: 1.6271 - acc: 0.5613 - 64ms/step
step  30/177 - loss: 1.6286 - acc: 0.5607 - 61ms/step
step  40/177 - loss: 1.6034 - acc: 0.5541 - 59ms/step
step  50/177 - loss: 1.6957 - acc: 0.5542 - 58ms/step
step  60/177 - loss: 1.6428 - acc: 0.5535 - 57ms/step
step  70/177 - loss: 1.6230 - acc: 0.5536 - 57ms/step
step  80/177 - loss: 1.6314 - acc: 0.5516 - 57ms/step
step  90/177 - loss: 1.5688 - acc: 0.5523 - 57ms/step
step 100/177 - loss: 1.6648 - acc: 0.5528 - 57ms/step
step 110/177 - loss: 1.6149 - acc: 0.5543 - 56ms/step
step 120/177 - loss: 1.6456 - acc: 0.5557 - 56ms/step
step 130/177 - loss: 1.6272 - acc: 0.5564 - 56ms/step
step 140/177 - loss: 1.5636 - acc: 0.5575 - 55ms/step
step 150/177 - loss: 1.6009 - acc: 0.5581 - 55ms/step
step 160/177 - loss: 1.6283 - acc: 0.5567 - 55ms/step
step 170/177 - loss: 1.5452 - acc: 0.5573 - 55ms/step
step 177/177 - loss: 1.5796 - acc: 0.5589 - 54ms/step
save checkpoint at /home/aistudio/dataset/checkpoints/5
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6851 - acc: 0.4898 - 55ms/step
step 20/45 - loss: 1.6844 - acc: 0.4855 - 45ms/step
step 30/45 - loss: 1.6766 - acc: 0.4818 - 42ms/step
step 40/45 - loss: 1.6813 - acc: 0.4797 - 40ms/step
step 45/45 - loss: 1.7277 - acc: 0.4807 - 37ms/step
Eval samples: 5650
Epoch 7/20
step  10/177 - loss: 1.6186 - acc: 0.5453 - 75ms/step
step  20/177 - loss: 1.6204 - acc: 0.5566 - 66ms/step
step  30/177 - loss: 1.6228 - acc: 0.5583 - 63ms/step
step  40/177 - loss: 1.5958 - acc: 0.5545 - 61ms/step
step  50/177 - loss: 1.6910 - acc: 0.5555 - 60ms/step
step  60/177 - loss: 1.6359 - acc: 0.5555 - 60ms/step
step  70/177 - loss: 1.6150 - acc: 0.5567 - 59ms/step
step  80/177 - loss: 1.6234 - acc: 0.5562 - 61ms/step
step  90/177 - loss: 1.5569 - acc: 0.5573 - 61ms/step
step 100/177 - loss: 1.6208 - acc: 0.5585 - 61ms/step
step 110/177 - loss: 1.5936 - acc: 0.5601 - 60ms/step
step 120/177 - loss: 1.6352 - acc: 0.5621 - 60ms/step
step 130/177 - loss: 1.6218 - acc: 0.5627 - 60ms/step
step 140/177 - loss: 1.5428 - acc: 0.5635 - 60ms/step
step 150/177 - loss: 1.5942 - acc: 0.5642 - 60ms/step
step 160/177 - loss: 1.6169 - acc: 0.5628 - 59ms/step
step 170/177 - loss: 1.5303 - acc: 0.5635 - 59ms/step
step 177/177 - loss: 1.5711 - acc: 0.5651 - 58ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6741 - acc: 0.4953 - 54ms/step
step 20/45 - loss: 1.6667 - acc: 0.4902 - 45ms/step
step 30/45 - loss: 1.6742 - acc: 0.4862 - 42ms/step
step 40/45 - loss: 1.6700 - acc: 0.4859 - 40ms/step
step 45/45 - loss: 1.7114 - acc: 0.4867 - 36ms/step
Eval samples: 5650
Epoch 8/20
step  10/177 - loss: 1.6065 - acc: 0.5594 - 68ms/step
step  20/177 - loss: 1.6147 - acc: 0.5645 - 60ms/step
step  30/177 - loss: 1.6249 - acc: 0.5656 - 57ms/step
step  40/177 - loss: 1.6093 - acc: 0.5611 - 56ms/step
step  50/177 - loss: 1.6914 - acc: 0.5608 - 55ms/step
step  60/177 - loss: 1.6303 - acc: 0.5604 - 56ms/step
step  70/177 - loss: 1.6111 - acc: 0.5616 - 56ms/step
step  80/177 - loss: 1.6102 - acc: 0.5613 - 56ms/step
step  90/177 - loss: 1.5508 - acc: 0.5628 - 56ms/step
step 100/177 - loss: 1.6150 - acc: 0.5642 - 56ms/step
step 110/177 - loss: 1.5882 - acc: 0.5656 - 56ms/step
step 120/177 - loss: 1.6340 - acc: 0.5672 - 56ms/step
step 130/177 - loss: 1.6166 - acc: 0.5677 - 56ms/step
step 140/177 - loss: 1.5224 - acc: 0.5686 - 56ms/step
step 150/177 - loss: 1.5861 - acc: 0.5695 - 56ms/step
step 160/177 - loss: 1.6150 - acc: 0.5680 - 56ms/step
step 170/177 - loss: 1.5256 - acc: 0.5685 - 56ms/step
step 177/177 - loss: 1.5626 - acc: 0.5700 - 55ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6826 - acc: 0.4938 - 53ms/step
step 20/45 - loss: 1.6713 - acc: 0.4887 - 44ms/step
step 30/45 - loss: 1.6761 - acc: 0.4852 - 41ms/step
step 40/45 - loss: 1.6710 - acc: 0.4834 - 40ms/step
step 45/45 - loss: 1.7004 - acc: 0.4837 - 36ms/step
Eval samples: 5650
Epoch 9/20
step  10/177 - loss: 1.6033 - acc: 0.5656 - 74ms/step
step  20/177 - loss: 1.6114 - acc: 0.5695 - 63ms/step
step  30/177 - loss: 1.6206 - acc: 0.5695 - 59ms/step
step  40/177 - loss: 1.5935 - acc: 0.5641 - 58ms/step
step  50/177 - loss: 1.6802 - acc: 0.5645 - 56ms/step
step  60/177 - loss: 1.6422 - acc: 0.5630 - 55ms/step
step  70/177 - loss: 1.6089 - acc: 0.5642 - 55ms/step
step  80/177 - loss: 1.6082 - acc: 0.5639 - 55ms/step
step  90/177 - loss: 1.5486 - acc: 0.5653 - 54ms/step
step 100/177 - loss: 1.6094 - acc: 0.5667 - 54ms/step
step 110/177 - loss: 1.5829 - acc: 0.5681 - 55ms/step
step 120/177 - loss: 1.6280 - acc: 0.5698 - 55ms/step
step 130/177 - loss: 1.6053 - acc: 0.5704 - 55ms/step
step 140/177 - loss: 1.5186 - acc: 0.5713 - 55ms/step
step 150/177 - loss: 1.5838 - acc: 0.5720 - 55ms/step
step 160/177 - loss: 1.6141 - acc: 0.5704 - 55ms/step
step 170/177 - loss: 1.5235 - acc: 0.5709 - 55ms/step
step 177/177 - loss: 1.5559 - acc: 0.5724 - 54ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6887 - acc: 0.4906 - 55ms/step
step 20/45 - loss: 1.6699 - acc: 0.4883 - 45ms/step
step 30/45 - loss: 1.6766 - acc: 0.4844 - 43ms/step
step 40/45 - loss: 1.6694 - acc: 0.4824 - 42ms/step
step 45/45 - loss: 1.6833 - acc: 0.4834 - 38ms/step
Eval samples: 5650
Epoch 10/20
step  10/177 - loss: 1.6022 - acc: 0.5641 - 76ms/step
step  20/177 - loss: 1.6135 - acc: 0.5707 - 67ms/step
step  30/177 - loss: 1.6182 - acc: 0.5724 - 64ms/step
step  40/177 - loss: 1.5896 - acc: 0.5662 - 62ms/step
step  50/177 - loss: 1.6780 - acc: 0.5663 - 61ms/step
step  60/177 - loss: 1.6367 - acc: 0.5652 - 60ms/step
step  70/177 - loss: 1.6045 - acc: 0.5663 - 60ms/step
step  80/177 - loss: 1.6211 - acc: 0.5654 - 60ms/step
step  90/177 - loss: 1.5481 - acc: 0.5669 - 60ms/step
step 100/177 - loss: 1.6071 - acc: 0.5684 - 59ms/step
step 110/177 - loss: 1.5824 - acc: 0.5700 - 59ms/step
step 120/177 - loss: 1.6334 - acc: 0.5715 - 59ms/step
step 130/177 - loss: 1.6030 - acc: 0.5721 - 59ms/step
step 140/177 - loss: 1.5168 - acc: 0.5729 - 59ms/step
step 150/177 - loss: 1.5817 - acc: 0.5736 - 59ms/step
step 160/177 - loss: 1.6144 - acc: 0.5721 - 59ms/step
step 170/177 - loss: 1.5222 - acc: 0.5726 - 59ms/step
step 177/177 - loss: 1.5573 - acc: 0.5740 - 58ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6844 - acc: 0.4914 - 62ms/step
step 20/45 - loss: 1.6720 - acc: 0.4887 - 51ms/step
step 30/45 - loss: 1.6747 - acc: 0.4849 - 48ms/step
step 40/45 - loss: 1.6692 - acc: 0.4838 - 45ms/step
step 45/45 - loss: 1.6808 - acc: 0.4846 - 41ms/step
Eval samples: 5650
Epoch 11/20
step  10/177 - loss: 1.6011 - acc: 0.5602 - 72ms/step
step  20/177 - loss: 1.6330 - acc: 0.5676 - 62ms/step
step  30/177 - loss: 1.6392 - acc: 0.5677 - 59ms/step
step  40/177 - loss: 1.5843 - acc: 0.5631 - 58ms/step
step  50/177 - loss: 1.6712 - acc: 0.5647 - 58ms/step
step  60/177 - loss: 1.6372 - acc: 0.5643 - 58ms/step
step  70/177 - loss: 1.5980 - acc: 0.5651 - 58ms/step
step  80/177 - loss: 1.6075 - acc: 0.5648 - 57ms/step
step  90/177 - loss: 1.5467 - acc: 0.5663 - 57ms/step
step 100/177 - loss: 1.6056 - acc: 0.5679 - 57ms/step
step 110/177 - loss: 1.5772 - acc: 0.5699 - 57ms/step
step 120/177 - loss: 1.6257 - acc: 0.5719 - 57ms/step
step 130/177 - loss: 1.6040 - acc: 0.5726 - 57ms/step
step 140/177 - loss: 1.5164 - acc: 0.5734 - 57ms/step
step 150/177 - loss: 1.5815 - acc: 0.5742 - 57ms/step
step 160/177 - loss: 1.6120 - acc: 0.5728 - 57ms/step
step 170/177 - loss: 1.5186 - acc: 0.5732 - 57ms/step
step 177/177 - loss: 1.5586 - acc: 0.5747 - 56ms/step
save checkpoint at /home/aistudio/dataset/checkpoints/10
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6713 - acc: 0.4961 - 61ms/step
step 20/45 - loss: 1.6517 - acc: 0.4953 - 50ms/step
step 30/45 - loss: 1.6924 - acc: 0.4904 - 47ms/step
step 40/45 - loss: 1.6653 - acc: 0.4895 - 45ms/step
step 45/45 - loss: 1.6903 - acc: 0.4906 - 41ms/step
Eval samples: 5650
Epoch 12/20
step  10/177 - loss: 1.5995 - acc: 0.5656 - 78ms/step
step  20/177 - loss: 1.6127 - acc: 0.5676 - 69ms/step
step  30/177 - loss: 1.6157 - acc: 0.5630 - 65ms/step
step  40/177 - loss: 1.6057 - acc: 0.5578 - 64ms/step
step  50/177 - loss: 1.6634 - acc: 0.5608 - 63ms/step
step  60/177 - loss: 1.6268 - acc: 0.5607 - 62ms/step
step  70/177 - loss: 1.6071 - acc: 0.5616 - 61ms/step
step  80/177 - loss: 1.6241 - acc: 0.5616 - 61ms/step
step  90/177 - loss: 1.5484 - acc: 0.5636 - 60ms/step
step 100/177 - loss: 1.6052 - acc: 0.5654 - 60ms/step
step 110/177 - loss: 1.5799 - acc: 0.5677 - 59ms/step
step 120/177 - loss: 1.6239 - acc: 0.5701 - 59ms/step
step 130/177 - loss: 1.6024 - acc: 0.5710 - 58ms/step
step 140/177 - loss: 1.5156 - acc: 0.5721 - 58ms/step
step 150/177 - loss: 1.5803 - acc: 0.5730 - 57ms/step
step 160/177 - loss: 1.6108 - acc: 0.5716 - 57ms/step
step 170/177 - loss: 1.5170 - acc: 0.5722 - 57ms/step
step 177/177 - loss: 1.5563 - acc: 0.5736 - 56ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6669 - acc: 0.4969 - 53ms/step
step 20/45 - loss: 1.6582 - acc: 0.4953 - 45ms/step
step 30/45 - loss: 1.6945 - acc: 0.4898 - 42ms/step
step 40/45 - loss: 1.6635 - acc: 0.4885 - 40ms/step
step 45/45 - loss: 1.6893 - acc: 0.4904 - 36ms/step
Eval samples: 5650
Epoch 13/20
step  10/177 - loss: 1.5915 - acc: 0.5703 - 74ms/step
step  20/177 - loss: 1.6069 - acc: 0.5723 - 65ms/step
step  30/177 - loss: 1.6184 - acc: 0.5729 - 62ms/step
step  40/177 - loss: 1.6018 - acc: 0.5680 - 60ms/step
step  50/177 - loss: 1.6628 - acc: 0.5677 - 59ms/step
step  60/177 - loss: 1.6385 - acc: 0.5674 - 59ms/step
step  70/177 - loss: 1.6005 - acc: 0.5683 - 59ms/step
step  80/177 - loss: 1.6023 - acc: 0.5682 - 58ms/step
step  90/177 - loss: 1.5418 - acc: 0.5700 - 58ms/step
step 100/177 - loss: 1.6041 - acc: 0.5713 - 58ms/step
step 110/177 - loss: 1.5813 - acc: 0.5733 - 57ms/step
step 120/177 - loss: 1.6230 - acc: 0.5751 - 57ms/step
step 130/177 - loss: 1.6058 - acc: 0.5757 - 56ms/step
step 140/177 - loss: 1.5128 - acc: 0.5765 - 56ms/step
step 150/177 - loss: 1.5791 - acc: 0.5771 - 56ms/step
step 160/177 - loss: 1.6202 - acc: 0.5752 - 57ms/step
step 170/177 - loss: 1.5141 - acc: 0.5757 - 57ms/step
step 177/177 - loss: 1.5553 - acc: 0.5770 - 56ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6652 - acc: 0.4953 - 60ms/step
step 20/45 - loss: 1.6590 - acc: 0.4941 - 50ms/step
step 30/45 - loss: 1.6944 - acc: 0.4878 - 46ms/step
step 40/45 - loss: 1.6642 - acc: 0.4867 - 44ms/step
step 45/45 - loss: 1.6927 - acc: 0.4887 - 40ms/step
Eval samples: 5650
Epoch 14/20
step  10/177 - loss: 1.5908 - acc: 0.5719 - 78ms/step
step  20/177 - loss: 1.6007 - acc: 0.5770 - 69ms/step
step  30/177 - loss: 1.6118 - acc: 0.5781 - 66ms/step
step  40/177 - loss: 1.5809 - acc: 0.5730 - 65ms/step
step  50/177 - loss: 1.6768 - acc: 0.5725 - 64ms/step
step  60/177 - loss: 1.6333 - acc: 0.5720 - 65ms/step
step  70/177 - loss: 1.5920 - acc: 0.5727 - 64ms/step
step  80/177 - loss: 1.6008 - acc: 0.5721 - 63ms/step
step  90/177 - loss: 1.5389 - acc: 0.5736 - 62ms/step
step 100/177 - loss: 1.5994 - acc: 0.5748 - 62ms/step
step 110/177 - loss: 1.5738 - acc: 0.5766 - 61ms/step
step 120/177 - loss: 1.6200 - acc: 0.5783 - 61ms/step
step 130/177 - loss: 1.6010 - acc: 0.5787 - 60ms/step
step 140/177 - loss: 1.5142 - acc: 0.5792 - 60ms/step
step 150/177 - loss: 1.5813 - acc: 0.5797 - 59ms/step
step 160/177 - loss: 1.6063 - acc: 0.5782 - 59ms/step
step 170/177 - loss: 1.5104 - acc: 0.5784 - 59ms/step
step 177/177 - loss: 1.5571 - acc: 0.5795 - 58ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6664 - acc: 0.4961 - 56ms/step
step 20/45 - loss: 1.6496 - acc: 0.4938 - 55ms/step
step 30/45 - loss: 1.7030 - acc: 0.4878 - 49ms/step
step 40/45 - loss: 1.6630 - acc: 0.4859 - 46ms/step
step 45/45 - loss: 1.7294 - acc: 0.4874 - 42ms/step
Eval samples: 5650
Epoch 15/20
step  10/177 - loss: 1.5916 - acc: 0.5711 - 71ms/step
step  20/177 - loss: 1.5941 - acc: 0.5758 - 64ms/step
step  30/177 - loss: 1.6048 - acc: 0.5781 - 61ms/step
step  40/177 - loss: 1.5679 - acc: 0.5738 - 59ms/step
step  50/177 - loss: 1.6539 - acc: 0.5742 - 58ms/step
step  60/177 - loss: 1.6081 - acc: 0.5746 - 57ms/step
step  70/177 - loss: 1.5679 - acc: 0.5772 - 57ms/step
step  80/177 - loss: 1.5710 - acc: 0.5796 - 56ms/step
step  90/177 - loss: 1.5171 - acc: 0.5852 - 56ms/step
step 100/177 - loss: 1.5883 - acc: 0.5883 - 56ms/step
step 110/177 - loss: 1.5529 - acc: 0.5916 - 56ms/step
step 120/177 - loss: 1.5993 - acc: 0.5945 - 56ms/step
step 130/177 - loss: 1.5754 - acc: 0.5956 - 55ms/step
step 140/177 - loss: 1.4962 - acc: 0.5970 - 55ms/step
step 150/177 - loss: 1.5856 - acc: 0.5984 - 55ms/step
step 160/177 - loss: 1.5679 - acc: 0.5975 - 55ms/step
step 170/177 - loss: 1.5013 - acc: 0.5988 - 55ms/step
step 177/177 - loss: 1.5302 - acc: 0.6005 - 54ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6809 - acc: 0.4828 - 56ms/step
step 20/45 - loss: 1.6551 - acc: 0.4836 - 46ms/step
step 30/45 - loss: 1.7061 - acc: 0.4789 - 44ms/step
step 40/45 - loss: 1.6714 - acc: 0.4754 - 43ms/step
step 45/45 - loss: 1.7768 - acc: 0.4768 - 39ms/step
Eval samples: 5650
Epoch 16/20
step  10/177 - loss: 1.5828 - acc: 0.6016 - 75ms/step
step  20/177 - loss: 1.5840 - acc: 0.6023 - 66ms/step
step  30/177 - loss: 1.5903 - acc: 0.6096 - 64ms/step
step  40/177 - loss: 1.5320 - acc: 0.6043 - 62ms/step
step  50/177 - loss: 1.6380 - acc: 0.6059 - 62ms/step
step  60/177 - loss: 1.5734 - acc: 0.6073 - 61ms/step
step  70/177 - loss: 1.5567 - acc: 0.6088 - 61ms/step
step  80/177 - loss: 1.5494 - acc: 0.6079 - 60ms/step
step  90/177 - loss: 1.5146 - acc: 0.6098 - 60ms/step
step 100/177 - loss: 1.5762 - acc: 0.6103 - 60ms/step
step 110/177 - loss: 1.5406 - acc: 0.6120 - 60ms/step
step 120/177 - loss: 1.6189 - acc: 0.6133 - 60ms/step
step 130/177 - loss: 1.5716 - acc: 0.6124 - 60ms/step
step 140/177 - loss: 1.4817 - acc: 0.6132 - 59ms/step
step 150/177 - loss: 1.5693 - acc: 0.6143 - 59ms/step
step 160/177 - loss: 1.5502 - acc: 0.6128 - 59ms/step
step 170/177 - loss: 1.4877 - acc: 0.6136 - 59ms/step
step 177/177 - loss: 1.5177 - acc: 0.6149 - 58ms/step
save checkpoint at /home/aistudio/dataset/checkpoints/15
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6829 - acc: 0.4734 - 56ms/step
step 20/45 - loss: 1.6523 - acc: 0.4738 - 46ms/step
step 30/45 - loss: 1.7036 - acc: 0.4693 - 43ms/step
step 40/45 - loss: 1.6898 - acc: 0.4674 - 41ms/step
step 45/45 - loss: 1.7567 - acc: 0.4683 - 38ms/step
Eval samples: 5650
Epoch 17/20
step  10/177 - loss: 1.5655 - acc: 0.6070 - 76ms/step
step  20/177 - loss: 1.5686 - acc: 0.6113 - 67ms/step
step  30/177 - loss: 1.5766 - acc: 0.6206 - 64ms/step
step  40/177 - loss: 1.5178 - acc: 0.6176 - 62ms/step
step  50/177 - loss: 1.6141 - acc: 0.6200 - 61ms/step
step  60/177 - loss: 1.5739 - acc: 0.6197 - 61ms/step
step  70/177 - loss: 1.5446 - acc: 0.6204 - 60ms/step
step  80/177 - loss: 1.5794 - acc: 0.6178 - 60ms/step
step  90/177 - loss: 1.5251 - acc: 0.6189 - 59ms/step
step 100/177 - loss: 1.5639 - acc: 0.6202 - 59ms/step
step 110/177 - loss: 1.5550 - acc: 0.6218 - 59ms/step
step 120/177 - loss: 1.5846 - acc: 0.6214 - 58ms/step
step 130/177 - loss: 1.5539 - acc: 0.6199 - 59ms/step
step 140/177 - loss: 1.4844 - acc: 0.6198 - 58ms/step
step 150/177 - loss: 1.5569 - acc: 0.6209 - 58ms/step
step 160/177 - loss: 1.5534 - acc: 0.6191 - 59ms/step
step 170/177 - loss: 1.4782 - acc: 0.6192 - 58ms/step
step 177/177 - loss: 1.5331 - acc: 0.6201 - 57ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6726 - acc: 0.4609 - 68ms/step
step 20/45 - loss: 1.6644 - acc: 0.4633 - 53ms/step
step 30/45 - loss: 1.7159 - acc: 0.4638 - 47ms/step
step 40/45 - loss: 1.6838 - acc: 0.4613 - 44ms/step
step 45/45 - loss: 1.7698 - acc: 0.4625 - 40ms/step
Eval samples: 5650
Epoch 18/20
step  10/177 - loss: 1.5593 - acc: 0.6047 - 71ms/step
step  20/177 - loss: 1.5594 - acc: 0.6156 - 62ms/step
step  30/177 - loss: 1.5772 - acc: 0.6232 - 59ms/step
step  40/177 - loss: 1.5094 - acc: 0.6201 - 58ms/step
step  50/177 - loss: 1.6093 - acc: 0.6223 - 57ms/step
step  60/177 - loss: 1.5515 - acc: 0.6240 - 57ms/step
step  70/177 - loss: 1.5516 - acc: 0.6238 - 57ms/step
step  80/177 - loss: 1.5329 - acc: 0.6237 - 57ms/step
step  90/177 - loss: 1.5007 - acc: 0.6264 - 57ms/step
step 100/177 - loss: 1.5695 - acc: 0.6273 - 57ms/step
step 110/177 - loss: 1.5344 - acc: 0.6286 - 57ms/step
step 120/177 - loss: 1.5720 - acc: 0.6299 - 57ms/step
step 130/177 - loss: 1.5521 - acc: 0.6294 - 58ms/step
step 140/177 - loss: 1.4849 - acc: 0.6296 - 57ms/step
step 150/177 - loss: 1.5788 - acc: 0.6298 - 57ms/step
step 160/177 - loss: 1.5385 - acc: 0.6277 - 57ms/step
step 170/177 - loss: 1.4677 - acc: 0.6278 - 57ms/step
step 177/177 - loss: 1.5113 - acc: 0.6292 - 56ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6822 - acc: 0.4727 - 60ms/step
step 20/45 - loss: 1.6542 - acc: 0.4770 - 50ms/step
step 30/45 - loss: 1.7106 - acc: 0.4727 - 47ms/step
step 40/45 - loss: 1.6821 - acc: 0.4721 - 45ms/step
step 45/45 - loss: 1.8195 - acc: 0.4717 - 41ms/step
Eval samples: 5650
Epoch 19/20
step  10/177 - loss: 1.5472 - acc: 0.6273 - 71ms/step
step  20/177 - loss: 1.5497 - acc: 0.6301 - 63ms/step
step  30/177 - loss: 1.5600 - acc: 0.6375 - 61ms/step
step  40/177 - loss: 1.5348 - acc: 0.6324 - 60ms/step
step  50/177 - loss: 1.5961 - acc: 0.6338 - 59ms/step
step  60/177 - loss: 1.5397 - acc: 0.6355 - 58ms/step
step  70/177 - loss: 1.5272 - acc: 0.6360 - 58ms/step
step  80/177 - loss: 1.5201 - acc: 0.6348 - 58ms/step
step  90/177 - loss: 1.4840 - acc: 0.6370 - 58ms/step
step 100/177 - loss: 1.5637 - acc: 0.6379 - 57ms/step
step 110/177 - loss: 1.5202 - acc: 0.6389 - 57ms/step
step 120/177 - loss: 1.5706 - acc: 0.6396 - 58ms/step
step 130/177 - loss: 1.5425 - acc: 0.6389 - 57ms/step
step 140/177 - loss: 1.4592 - acc: 0.6402 - 57ms/step
step 150/177 - loss: 1.5813 - acc: 0.6405 - 57ms/step
step 160/177 - loss: 1.5964 - acc: 0.6368 - 57ms/step
step 170/177 - loss: 1.4696 - acc: 0.6349 - 57ms/step
step 177/177 - loss: 1.5041 - acc: 0.6351 - 56ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6782 - acc: 0.4703 - 55ms/step
step 20/45 - loss: 1.6487 - acc: 0.4730 - 45ms/step
step 30/45 - loss: 1.7122 - acc: 0.4682 - 42ms/step
step 40/45 - loss: 1.6939 - acc: 0.4658 - 41ms/step
step 45/45 - loss: 1.8219 - acc: 0.4655 - 37ms/step
Eval samples: 5650
Epoch 20/20
step  10/177 - loss: 1.5434 - acc: 0.6344 - 70ms/step
step  20/177 - loss: 1.5447 - acc: 0.6367 - 64ms/step
step  30/177 - loss: 1.5635 - acc: 0.6432 - 62ms/step
step  40/177 - loss: 1.5510 - acc: 0.6373 - 62ms/step
step  50/177 - loss: 1.5935 - acc: 0.6348 - 60ms/step
step  60/177 - loss: 1.5383 - acc: 0.6355 - 58ms/step
step  70/177 - loss: 1.5260 - acc: 0.6367 - 58ms/step
step  80/177 - loss: 1.5139 - acc: 0.6364 - 58ms/step
step  90/177 - loss: 1.4742 - acc: 0.6391 - 58ms/step
step 100/177 - loss: 1.5477 - acc: 0.6409 - 58ms/step
step 110/177 - loss: 1.5256 - acc: 0.6424 - 58ms/step
step 120/177 - loss: 1.5658 - acc: 0.6429 - 59ms/step
step 130/177 - loss: 1.5360 - acc: 0.6428 - 59ms/step
step 140/177 - loss: 1.4528 - acc: 0.6443 - 59ms/step
step 150/177 - loss: 1.5575 - acc: 0.6452 - 58ms/step
step 160/177 - loss: 1.5257 - acc: 0.6422 - 58ms/step
step 170/177 - loss: 1.4495 - acc: 0.6424 - 58ms/step
step 177/177 - loss: 1.5107 - acc: 0.6432 - 57ms/step
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6787 - acc: 0.4602 - 60ms/step
step 20/45 - loss: 1.6627 - acc: 0.4582 - 50ms/step
step 30/45 - loss: 1.7386 - acc: 0.4547 - 48ms/step
step 40/45 - loss: 1.7037 - acc: 0.4514 - 46ms/step
step 45/45 - loss: 1.7308 - acc: 0.4526 - 42ms/step
Eval samples: 5650
save checkpoint at /home/aistudio/dataset/checkpoints/final
results = model.evaluate(dev_loader)
print("Finally test acc: %.5f" % results['acc'])
Eval begin...
The loss value printed in the log is the current batch, and the metric is the average value of previous step.
step 10/45 - loss: 1.6787 - acc: 0.4602 - 56ms/step
step 20/45 - loss: 1.6627 - acc: 0.4582 - 46ms/step
step 30/45 - loss: 1.7386 - acc: 0.4547 - 43ms/step
step 40/45 - loss: 1.7037 - acc: 0.4514 - 41ms/step
step 45/45 - loss: 1.7308 - acc: 0.4526 - 37ms/step
Eval samples: 5650
Finally test acc: 0.45257
label_map={
     0:"sadness", 1:"happiness",2:"disgust",3:"like",4:"anger" ,5:"surprise",6:"fear"}
results = model.predict(test_loader, batch_size=128)[0]
predictions = []

for batch_probs in results:
    # 映射分类label
    idx = np.argmax(batch_probs, axis=-1)
    idx = idx.tolist()
    labels = [label_map[i] for i in idx]
    predictions.extend(labels)

# 看看预测数据前5个样例分类结果
for idx, data in enumerate(test_ds.data[:10]):
 idx, data in enumerate(test_ds.data[:10]):
    print('Data: {} \t Label: {}'.format(data[0], predictions[idx]))
Predict begin...
step 56/56 [==============================] - ETA: 4s - 85ms/ste - ETA: 4s - 88ms/ste - ETA: 3s - 72ms/ste - ETA: 3s - 64ms/ste - ETA: 2s - 60ms/ste - ETA: 2s - 56ms/ste - ETA: 2s - 54ms/ste - ETA: 2s - 52ms/ste - ETA: 1s - 51ms/ste - ETA: 1s - 50ms/ste - ETA: 1s - 49ms/ste - ETA: 1s - 48ms/ste - ETA: 1s - 47ms/ste - ETA: 1s - 46ms/ste - ETA: 1s - 46ms/ste - ETA: 1s - 46ms/ste - ETA: 0s - 45ms/ste - ETA: 0s - 45ms/ste - ETA: 0s - 45ms/ste - ETA: 0s - 45ms/ste - ETA: 0s - 45ms/ste - ETA: 0s - 44ms/ste - ETA: 0s - 44ms/ste - ETA: 0s - 44ms/ste - ETA: 0s - 44ms/ste - ETA: 0s - 43ms/ste - ETA: 0s - 41ms/ste - 40ms/step          
Predict samples: 7063
Data: 【旅游】美食:滇南地区建水的蕈芽、石屏的豆腐、蒙自的过桥米线。滇东北地区菜豆花、连渣搞、酸辣鸡等。滇西地区的大理沙锅鱼、酸辣鱼。丽江粑粑、八大碗。弥渡的卷蹄、风吹肝、腾冲的大救驾,各种凉拌野菜、松尖等。关注【游遍云南】公众微信,让您畅游云南,游遍云南公众微信号:y4000119001 	 Label: happiness
Data: 想哭, 	 Label: sadness
Data: 自己打的赌,赌的很大,不知道自己到底战绩怎样 	 Label: disgust
Data: 4...这都不是偶然的事情,这是他明白这个事实真相,对生死看得很淡薄,知道要认真努力修行,所以死了之后,自己可以作主,自己可以选择到哪一道去。如果在临终时,一慌一乱,你对身体很留恋,对家亲眷属很留恋,那你往往就到三途去了! 	 Label: happiness
Data: 干了这碗香菜我们是好朋友 	 Label: disgust
Data: 韩国沉船遇难者'不愿分离'。一男生一女生害怕被水冲开分离紧捆绑在一起。[蜡烛][蜡烛][蜡烛] 	 Label: happiness
Data: 那一年,苍井空还是处女,冠希还没有相机,李刚还没有儿子,菊花只是一种花,企鹅不是qq,2b我只知道是铅笔,买方便面还有调料,杯具只是用来刷牙,楼房是用来住的,黄瓜香蕉只是用来吃的,教授还不是叫兽,太阳还不叫日,领导不会写日记,鸭梨还没有这么大,肚子大了也知道是谁的我们还相信真情 	 Label: sadness
Data: 小孩子会说谎,大孩子也会说谎,不过,美名其曰为“借口”,不努力,是因为没了目标,没了动力,习惯了堕落。。。 	 Label: sadness
Data: 特困户的春天[拜拜] 	 Label: sadness
Data: 找院长写推荐信之前把自我介绍想过很多遍,结果院长大人没有赴约;从早到晚在实验室忙碌只为了按时完成实验,结果教授将实验计划改变;纠结了好久今天终于鼓起勇气再加一次某人的微信,结果我貌似在黑名单里面......总以为解决了自己就解决了一切,但是没想到,事情总是有想不懂到的一面。 	 Label: disgust

你可能感兴趣的:(笔记,paddlepaddle,python)