Open ZefengHan opened 5 years ago
我想把这个程序改成多分类的情况,我在做目标情感分析,是三分类的,主要问题在那些评价指标的改动上?望指教。
1,修改config类中的num_classes为三类 2, trainLabels, evalLabels等要用one-hot的向量表示,向量长度为num_classes 3,修改self.inputY = tf.placeholder(tf.float32, [None, config.num_classes], name="inputY") 4, 修改输出,outputW中的shape=[outputSize, config.num_classes], outputB = [config.num_classes] 5 修改self.predictions = tf.argmax(self.logits) 其中self.logits = tf.nn.xw_plus_b(output, outputW, outputB, name="predictions") 6,在计算损失时,将losses = tf.nn.sigmoid_cross_entropy_with_logits(logits=self.predictions, labels=self.inputY) 修改为losses = tf.nn.softmax_cross_entropy_with_logits(logits=self.logits, labels=self.inputY) 你可以先试下,要改的应该就这些了,主要是output层,二分类时输出层是一个神经元,三分类时是三个神经元。
你好 在改成三分类的时候遇到另外一个问题 全连接层这里还是二分类器的函数,出来的self.predictions形状是,(3,),里面的数据类型是inter32,我该改成哪种预测函数,望指教 self.binaryPreds = tf.cast(tf.greater_equal(self.predictions, 0.5), tf.float32, name="binaryPreds") 报错如下:TypeError: Expected int64 passed to parameter 'y' of op 'GreaterEqual', got 0.5 of type 'float' instead.
1,修改self.predictions = tf.argmax(self.logits, -1),这行代码就已经会得到每个类别,输出的是label的index 2,删除self.binaryPreds,这个现在没什么用,但是在模型训练的代码中,如: _, summary, step, loss, predictions, binaryPreds = sess.run( [trainOp, summaryOp, globalStep, lstm.loss, lstm.predictions, lstm.binaryPreds], feed_dict) 你需要把这个lstm.binaryPreds给删了,因为已经没有这个属性了。 3,在性能指标计算中,你也需要针对多分类计算相应的性能指标,这个已经不适用了
1.谢谢解答,代码已经改成下面这样了?模型已经能够训练了,也就是说性能指标我得自己重新定义新的多标签性能指标,里面性能指标的结果是不是不参与训练的过程? 2.还有一个问题 模型保存图片如下,我只要把代码取消注释到目前行是不是就可以了? 3.checkpoint文件的测试程序在代码压缩包里有吗?
请问,你有测试过多分类的各个模型结果吗?
1.谢谢解答,代码已经改成下面这样了?模型已经能够训练了,也就是说性能指标我得自己重新定义新的多标签性能指标,里面性能指标的结果是不是不参与训练的过程? 2.还有一个问题 模型保存图片如下,我只要把代码取消注释到目前行是不是就可以了? 3.checkpoint文件的测试程序在代码压缩包里有吗?
1,是的,性能指标是不参与训练的 2,这是一种模型的保存方式,会保存为checkpoint文件,下面注释的代码是保存为pb文件的,pb文件可以用tensorflow serving 部署 3,预测代码这里没有,你可以看我这篇博客:https://www.cnblogs.com/jiangxinyang/p/10022216.html。这里有加载模型进行预测的代码。
太感谢了!多谢指教!
请问,你有测试过多分类的各个模型结果吗?
你好,目前还没有在同一份多分类数据集上跑过这些模型,你可以试下,稍微修改下代码就可以实现。
太感谢了!多谢指教!
不客气
请问,你有测试过多分类的各个模型结果吗?
测试文件还没写好等写好了测试下和你说
请问,你有测试过多分类的各个模型结果吗?
测试文件还没写好等写好了测试下和你说
可以的,有问题可以问我
请问,你有测试过多分类的各个模型结果吗?
测试文件还没写好等写好了测试下和你说
我用自测集测试了text-cnn,bi-lstm,bi-lstm+att和bert,结果是bert>bi-lstm+att==text-cnn>bi-lstm,其他的就还没有训练和测试了
是的,一般也是推荐使用bert,Bi-LSTM+ATT, textCNN,还有Transformer可以试试,一般Transformer推荐数据量比较大的时候使用。Bi-LSTM不太好使,调参比较难,很难收敛。
是的,一般也是推荐使用bert,Bi-LSTM+ATT, textCNN,还有Transformer可以试试,一般Transformer推荐数据量比较大的时候使用。Bi-LSTM不太好使,调参比较难,很难收敛。
有尝试过深层模型比如residual Bi-lstm或者stacked highway Bi-lstm吗? 分类问题太浅了,不知道适不适合使用这种深层模型
@jiangxinyang227 要怎么调用prediction的中间结果,比如各个分类的结果
@jiangxinyang227 要怎么调用prediction的中间结果,比如各个分类的结果 你好 ,不太明白是什么意思,一般来说你在prediction时想要拿到某个结果,你只要把这个结果的tensor加载出来,然后再加入到sess.run中就可以了
你好,作者,在编写测试文件的时候遇到了困难,望解答
麻烦问一下,根据上述的步骤修改代码,出现如下问题: ValueError: Invalid shape initializing RNN_0/RNN/MultiRNNCell/Cell0/LSTMCell/W_0, got [32, 16384], expected (1024, 16384) 您有遇到过吗?
上面那个程序是改transformer的,看你这个好像改的是lstm的,看你这个应该是维度错误,好像是batch数不对吧 你再从错的位置往上顺顺。这样我看不出来
上面那个程序是改transformer的,看你这个好像改的是lstm的,看你这个应该是维度错误,好像是batch数不对吧 你再从错的位置往上顺顺。这样我看不出来
能定位到问题在这里,bilim/model.py
上面那个程序是改transformer的,看你这个好像改的是lstm的,看你这个应该是维度错误,好像是batch数不对吧 你再从错的位置往上顺顺。这样我看不出来
是否方便加一下您的个人联系方式?我在做文本三分类,琢磨了一天啦,一直没找到特别好的解决方式。 @ZefengHan
我也没太看出来,你得看哪里用到了这个函数,然后应该就能找到这个shape输入的是多少了,具体我手上也没有你的那个程序也不好改,反正Python自带的包和函数肯定是不会错的 错的只能是自己的程序
你要是不介意咱们可以私聊,你留下可以留的联系方式,那样应该好改一些
你要是不介意咱们可以私聊,你留下可以留的联系方式,那样应该好改一些
可以麻烦您把多分类的代码发我一份吗?谢谢
你要是不介意咱们可以私聊,你留下可以留的联系方式,那样应该好改一些
你好,可以麻烦您分享下您的多分类code么,我微信是13261195210. 也是在弄emotion classifier。谢啦
可以留下你的邮箱吗?
------------------ 原始邮件 ------------------ 发件人: "Jiangchenglin521"notifications@github.com; 发送时间: 2019年5月22日(星期三) 上午10:20 收件人: "jiangxinyang227/textClassifier"textClassifier@noreply.github.com; 抄送: "韩泽峰"742505860@qq.com; "Mention"mention@noreply.github.com; 主题: Re: [jiangxinyang227/textClassifier] how to change the procedure into3-classifier? (#2)
你要是不介意咱们可以私聊,你留下可以留的联系方式,那样应该好改一些
你好,可以麻烦您分享下您的多分类code么,我微信是13261195210. 也是在弄emotion classifier。谢啦
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
可以留下你的邮箱吗? … ------------------ 原始邮件 ------------------ 发件人: "Jiangchenglin521"notifications@github.com; 发送时间: 2019年5月22日(星期三) 上午10:20 收件人: "jiangxinyang227/textClassifier"textClassifier@noreply.github.com; 抄送: "韩泽峰"742505860@qq.com; "Mention"mention@noreply.github.com; 主题: Re: [jiangxinyang227/textClassifier] how to change the procedure into3-classifier? (#2) 你要是不介意咱们可以私聊,你留下可以留的联系方式,那样应该好改一些 你好,可以麻烦您分享下您的多分类code么,我微信是13261195210. 也是在弄emotion classifier。谢啦 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
可以留下你的邮箱吗? … ------------------ 原始邮件 ------------------ 发件人: "Jiangchenglin521"notifications@github.com; 发送时间: 2019年5月22日(星期三) 上午10:20 收件人: "jiangxinyang227/textClassifier"textClassifier@noreply.github.com; 抄送: "韩泽峰"742505860@qq.com; "Mention"mention@noreply.github.com; 主题: Re: [jiangxinyang227/textClassifier] how to change the procedure into3-classifier? (#2) 你要是不介意咱们可以私聊,你留下可以留的联系方式,那样应该好改一些 你好,可以麻烦您分享下您的多分类code么,我微信是13261195210. 也是在弄emotion classifier。谢啦 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
可以留下你的邮箱吗? … ------------------ 原始邮件 ------------------ 发件人: "Jiangchenglin521"notifications@github.com; 发送时间: 2019年5月22日(星期三) 上午10:20 收件人: "jiangxinyang227/textClassifier"textClassifier@noreply.github.com; 抄送: "韩泽峰"742505860@qq.com; "Mention"mention@noreply.github.com; 主题: Re: [jiangxinyang227/textClassifier] how to change the procedure into3-classifier? (#2) 你要是不介意咱们可以私聊,你留下可以留的联系方式,那样应该好改一些 你好,可以麻烦您分享下您的多分类code么,我微信是13261195210. 也是在弄emotion classifier。谢啦 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
好的好的,13019925478@163.com
已分享
------------------ 原始邮件 ------------------ 发件人: "Jiangchenglin521"notifications@github.com; 发送时间: 2019年5月22日(星期三) 晚上7:29 收件人: "jiangxinyang227/textClassifier"textClassifier@noreply.github.com; 抄送: "韩泽峰"742505860@qq.com;"Mention"mention@noreply.github.com; 主题: Re: [jiangxinyang227/textClassifier] how to change the procedure into3-classifier? (#2)
可以留下你的邮箱吗? … ------------------ 原始邮件 ------------------ 发件人: "Jiangchenglin521"notifications@github.com; 发送时间: 2019年5月22日(星期三) 上午10:20 收件人: "jiangxinyang227/textClassifier"textClassifier@noreply.github.com; 抄送: "韩泽峰"742505860@qq.com; "Mention"mention@noreply.github.com; 主题: Re: [jiangxinyang227/textClassifier] how to change the procedure into3-classifier? (#2) 你要是不介意咱们可以私聊,你留下可以留的联系方式,那样应该好改一些 你好,可以麻烦您分享下您的多分类code么,我微信是13261195210. 也是在弄emotion classifier。谢啦 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
可以留下你的邮箱吗? … ------------------ 原始邮件 ------------------ 发件人: "Jiangchenglin521"notifications@github.com; 发送时间: 2019年5月22日(星期三) 上午10:20 收件人: "jiangxinyang227/textClassifier"textClassifier@noreply.github.com; 抄送: "韩泽峰"742505860@qq.com; "Mention"mention@noreply.github.com; 主题: Re: [jiangxinyang227/textClassifier] how to change the procedure into3-classifier? (#2) 你要是不介意咱们可以私聊,你留下可以留的联系方式,那样应该好改一些 你好,可以麻烦您分享下您的多分类code么,我微信是13261195210. 也是在弄emotion classifier。谢啦 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
可以留下你的邮箱吗? … ------------------ 原始邮件 ------------------ 发件人: "Jiangchenglin521"notifications@github.com; 发送时间: 2019年5月22日(星期三) 上午10:20 收件人: "jiangxinyang227/textClassifier"textClassifier@noreply.github.com; 抄送: "韩泽峰"742505860@qq.com; "Mention"mention@noreply.github.com; 主题: Re: [jiangxinyang227/textClassifier] how to change the procedure into3-classifier? (#2) 你要是不介意咱们可以私聊,你留下可以留的联系方式,那样应该好改一些 你好,可以麻烦您分享下您的多分类code么,我微信是13261195210. 也是在弄emotion classifier。谢啦 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
好的好的,13019925478@163.com
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
你好,我也是想改成多分类,想基于二分类把最后一层sigmoid函数改为softmax,在编码label时,我用的tf.one_hot(),其他的输出和w的维度按上面改的; 训练时,出现这样的错误:
TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.For reference, the tensor object was Tensor("one_hot:0", shape=(128, 1, 2), dtype=float32) which was passed to the feed with key Tensor("inputY:0", shape=(?, 2), dtype=float32).
请帮忙看一下@ZefengHan@Jiangchenglin521 谢谢
这里报错写的feed给模型的数据格式不对,你把你onehot的tensor给np.array一下试试
发自我的iPhone
------------------ Original ------------------ From: Veyronl notifications@github.com Date: Tue,Jul 16,2019 4:10 PM To: jiangxinyang227/textClassifier textClassifier@noreply.github.com Cc: ZefengHan 742505860@qq.com, Mention mention@noreply.github.com Subject: Re: [jiangxinyang227/textClassifier] how to change the procedure into 3-classifier? (#2)
调整了下,现在可以正常训练了,我再写个metric函数试试,
大佬,测试的部分你写了吗?@ZefengHan 我看你发的链接是模型保存和加载的;
准备放弃tensorflow转投torch和keras了
测试的部分忘记写没写了。好长时间没看这个代码了。测试的话应该加载进模型就可以测试了吧。网上搜一个测试代码教程应该很快就能实现
发自我的iPhone
------------------ Original ------------------ From: Veyronl notifications@github.com Date: Tue,Jul 16,2019 4:52 PM To: jiangxinyang227/textClassifier textClassifier@noreply.github.com Cc: ZefengHan 742505860@qq.com, Mention mention@noreply.github.com Subject: Re: [jiangxinyang227/textClassifier] how to change the procedure into 3-classifier? (#2)
调整了下,现在可以正常训练了,我再写个metric函数试试,
大佬,测试的部分你写了吗?@ZefengHan 我看你发的链接是模型保存和加载的;
准备放弃tensorflow转投torch和keras了
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
您好,请问能分享一份Transformer多分类和用模型来预测的代码吗?我自己改了几天总是出Bug。我的邮箱是522364642@qq.com,谢谢。 @ZefengHan @jiangxinyang227
1,修改config类中的num_classes为三类 2, trainLabels, evalLabels等要用one-hot的向量表示,向量长度为num_classes 3,修改self.inputY = tf.placeholder(tf.float32, [None, config.num_classes], name="inputY") 4, 修改输出,outputW中的shape=[outputSize, config.num_classes], outputB = [config.num_classes] 5 修改self.predictions = tf.argmax(self.logits) 其中self.logits = tf.nn.xw_plus_b(output, outputW, outputB, name="predictions") 6,在计算损失时,将losses = tf.nn.sigmoid_cross_entropy_with_logits(logits=self.predictions, labels=self.inputY) 修改为losses = tf.nn.softmax_cross_entropy_with_logits(logits=self.logits, labels=self.inputY) 你可以先试下,要改的应该就这些了,主要是output层,二分类时输出层是一个神经元,三分类时是三个神经元。
请问第二条,用one-hot的向量表示应该怎么修改呢?谢谢
how to change the procedure into 3-classifier? I want to change the procedure into a 3-classifier,which is about aspect based sentiment anysize. Thank you!