给定一组单词V,我想将同义词分组在一起V。我想知道 NLTK 和 Wordnet 中是否有任何内置函数可以作为V输入并根据同义词自动对它们进行聚类。
我已经知道如何提取每个单词的同义词,但这不是我想要的。如果我这样做,当同义词集彼此相交或成为彼此的子集/超集时,问题就会变得复杂,这需要编写一个函数来消除冲突。
作为一个例子,让我们考虑
V = ["good","constipate","bad","nice","defective","right","respectable","powerful"]
Run Code Online (Sandbox Code Playgroud)
我想要得到的输出是:
[('constipate'), ('nice'), ('bad', 'defective'), ('good', 'powerful', 'respectable', 'right')]
Run Code Online (Sandbox Code Playgroud)
现在,根据簇的大小/数量,某些集合可能会分成多个集合,或组合在一起。在这里,我只关心 中的单词V及其同义词V。
我想Y = M_1*X_1 + M_2*X_2使用sklearn多维输入和输出样本(例如向量)训练线性模型。我尝试了以下代码:
from sklearn import linear_model
from pandas import DataFrame
x1 = [[1,2],[2,3],[3,4]]
x2 = [[1,1],[3,2],[3,5]]
y = [[1,0],[1,2],[2,3]]
model = {
'vec1': x1,
'vec2': x2,
'compound_vec': y}
df = DataFrame(model, columns=['vec1','vec2','compound_vec'])
x = df[['vec1','vec2']].astype(object)
y = df['compound_vec'].astype(object)
regr = linear_model.LinearRegression()
regr.fit(x,y)
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
regr.fit(x,y)
...
array = array.astype(np.float64)
ValueError: setting an array element with a sequence.
Run Code Online (Sandbox Code Playgroud)
有谁知道代码有什么问题?如果这是一种正确的训练方式Y = M_1*X_1 + M_2*X_2?