【发布时间】:2021-05-06 21:12:25
【问题描述】:
我有一系列标记化的短语。然后我找到了每个单词的同义词,并将它们保存在字典中,单词(即令牌)作为键,同义词列表作为值。我的目标是通过用同义词替换每个单词来生成新短语并创建新短语。
例如,我们有一个包含 3 个标记的短语。第一个标记(有限)有 18 个同义词,第二个标记(社交)有 4 个同义词,最后一个标记(支持)有 16 个同义词。所以理论上我们可以通过将所有 3 个列表组合在一起来获得 18 * 4 * 16 = 1,152 新短语。
phrases = ['limited', 'social', 'support']
dictionary = {
'limited': ['express', 'limited', 'restrict', 'restrain', 'trammel', 'limit', 'bound', 'confine', 'throttle', 'circumscribe', 'specify', 'set', 'determine', 'define', 'fix', 'circumscribed', 'modified', 'special'],
'social': ['sociable', 'social', 'mixer', 'societal'],
'support': ['support', 'reinforcement', 'reenforcement', 'documentation', 'keep', 'livelihood', 'living', 'bread_and_butter', 'sustenance', 'supporting', 'accompaniment', 'musical_accompaniment', 'backup', 'financial_support', 'funding', 'backing']
}
new_phrases = [['express', 'sociable', 'support'], ['express', 'social', 'support'], ['express', 'mixer', 'support'], ['express', 'societal', 'support'], ..., [...]]
我的尝试是遍历每个列表中的项目,但我很难概念化如何将这 3 个列表组合在一起以生成类似于 new_phrases 的内容,如上面的代码块所示。
for word in phrases:
print("\nthe word is:", word)
print("list of synonyms is:", dictionary[word])
print("the list has", len(dictionary[word]), "elements")
for syn in dictionary[word]:
print("a synonmy is:", syn)
【问题讨论】:
标签: python for-loop nlp data-augmentation