我是NLP世界的新手,但是想知道目前是否有任何简单的方法(使用服务或OSS等)使用NLP来改变大量文本的主题,其中原始主题是已知的(并且最好是这样的)一种方法有多种语言可用?)(相当于方法句子()。toPastTense()详细/可用:https://nlp-compromise.github.io)
让我们说原始文本是关于“你”的,你知道总是如此,但你想自动生成一个版本的文本,将被改为关于“你的兄弟”
(非常荒谬的)例子:
“当你到达角落时,你应该沿着大厅走下去。”
会变成
“你的兄弟应该走到大厅,当他到达角落时,他已经完成了。”
据我所知,这种类型的文本转换依赖于lemmatisation(如本文https://towardsdatascience.com/introduction-to-natural-language-processing-for-text-df845750fb63所示),但是由于我一直在研究文本转换方法,我还没有看到任何与句子主题相关的方法?
我不知道有什么副手,但肯定可以做到。例如,使用TextBlob,您可以尝试使用词性来提出功能。显然你在这里需要的不仅仅是这个小片段,就像检查主题/动词协议的功能一样,但它是一种方法的例子,希望它是值得深思的。
from textblob import TextBlob
from textblob.taggers import NLTKTagger
from textblob import Word
def lil_subj_replacer(phrase,input_subj,input_prp):
nltk_tagger = NLTKTagger()
blob = TextBlob(phrase,pos_tagger=nltk_tagger)
subject = True
for i,keyval in enumerate(blob.pos_tags):
key = keyval[0]
value = keyval[1]
if (value == 'PRP'):
if subject:
blob.words[i] = input_subj
subject = False
else:
blob.words[i] = input_prp
blob.words[i+1] = Word(blob.words[i+1]).lemmatize('v')
return ' '.join(blob.words)
my_phrase = 'You should go down the hall, as you reach the corner you are done.'
print(my_phrase)
print(lil_subj_replacer(phrase=my_phrase,input_subj='Your brother',input_prp='he'))
原文:You should go down the hall, as you reach the corner you are done.
没有lemmatize:Your brother should go down the hall as he reach the corner he are done
lemmatized动词:Your brother should go down the hall as he reach the corner he be done
编辑:添加了lemmaz的例子,因为你提到了它。