gpt4 book ai didi

deep-learning - 句子的序列标记而不是标记

转载 作者:行者123 更新时间:2023-12-04 10:38:23 26 4
gpt4 key购买 nike

我有属于一个段落的句子。每个句子都有一个标签。
[s1,s2,s3,…], [l1,l2,l3,…]
我知道我必须使用编码器对每个句子进行编码,然后使用序列标记。你能指导我如何做到这一点,将它们结合起来吗?

最佳答案

如果我正确理解您的问题,您正在寻找将您的句子编码为数字表示的方法。

假设您有以下数据:

data = ["Sarah, is that you? Hahahahahaha  Todd give you another black eye??"
"Well, being slick comes with the job of being a propagandist, Andi..."
"Sad to lose a young person who was earnestly working for the common good and public safety when so many are in the basement smoking pot and playing computer games."]

labels = [0,1,0]

现在你想建立一个分类器,训练分类器数据应该是数字格式,所以在这里我们将文本数据转换为数字结构,我们将使用 tf-idf 矢量化器,它将为文本数据创建矩阵,然后应用任何算法。
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.svm import LinearSVC
from sklearn.pipeline import Pipeline

vectorizerPipe = Pipeline([
('tfidf', TfidfVectorizer(lowercase=True,stop_words='english')),
('classification', LinearSVC(penalty='l2',loss='hinge'))])

trained_model = vectorizerPipe.fit(data,labels)

这里构建了管道,第一步是特征向量提取(将文本数据转换为数字格式),下一步我们将对其应用算法。您可以尝试这两个步骤中的很多参数。
稍后我们使用 .fit 方法启动管道并传递数据和标签。

关于deep-learning - 句子的序列标记而不是标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60048900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com