李宏毅作业4-语句情感判断

李宏毅老师的作业四也同样是不好对付的,这次我仍然用TensorFlow实现一遍,记录踩坑过程。

迫于心疼我的笔电,这次作业在Kaggle编写程式、而本次作业的数据集,Kaggle上也有现成的。

附上课程作业4的Kaggle地址:点击前往

Introduction for HomeWork

给的数据文件夹总共有三个档案
在这里插入图片描述

  • training_label.txt:有 label 的 training data(句子配上 0-negative or 1-postive,+++$+++ 是分隔符)

  • e.g., 1 +++$+++ are wtf … awww thanks !

  • training_nolabel.txt:沒有 label 的 training data(只有句子),用做 semi-supervised learning

  • e.g: hates being this burnt !! ouch

  • testing_data.txt:你要判断 testing data 里的句子是 0 or 1

    id,text

    0,my dog ate our dinner . no , seriously … he ate it .

    1,omg last day sooon n of primary noooooo x im gona be swimming out of school wif the amount of tears am gona cry

    2,stupid boys … they ’ re so … stupid !

Load Data and Word2Vector

拷贝ExampleCode的函数式:

def load_training_data(path='data/training_label.txt'):
    if 'training_label' in path:
        with open(path, 'r') as f:
            lines = f.readlines()
            lines = [line.strip('\n').split(' ') for line in lines]
        x = [line[2:] for line in lines]
        y = [line[0] for line in lines]
        return x, y
    else:
        with open(path, 'r') as f:
            lines = f.readlines()
            x = [line.strip('\n').split(' ') for line in lines]
        return x
def load_testing_data(path='data/testing_data'):
    with open(path, 'r') as f:
        lines = f.readlines()
        X = ["".join(line.strip('\n').split(",")[1:])
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值