【问题标题】:NLP text transformation Changing subjectNLP 文本转换 更改主题
【发布时间】:2019-09-04 19:20:21
【问题描述】:

我是 NLP 领域的新手,但想知道目前是否有任何简单的方法(使用服务或 OSS 等)在原始主题已知的情况下使用 NLP 更改大量文本的主题(以及如果这样的方法可以在多种语言中使用,最好?)(相当于方法 sentence().toPastTense() 详细/可在此处获得:https://nlp-compromise.github.io

假设原始文本是关于“你”的,并且您知道情况总是如此,但您想自动生成一个文本版本,将其更改为“你的兄弟”

(非常荒谬)示例:

“你应该走下大厅,当你到达拐角处时,你就完成了。”

会变成

“你的兄弟应该走下大厅,当他到达拐角处时 完成。”

据我了解,这种类型的文本转换依赖于词形还原(正如这篇文章 https://towardsdatascience.com/introduction-to-natural-language-processing-for-text-df845750fb63 所展示的那样),但由于我一直在研究文本转换方法,我还没有看到任何与该主题相关的方法句子?

【问题讨论】:

    标签: nlp


    【解决方案1】:

    我不知道有什么副手,但肯定可以做到。例如,使用TextBlob,您可以尝试使用词性提出一个功能。显然,您需要的不仅仅是这个小 sn-p,比如检查主语/动词一致性的函数,但它是一种方法的示例,希望它是值得深思的。

    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.

    没有词形还原:Your brother should go down the hall as he reach the corner he are done

    词形化动词:Your brother should go down the hall as he reach the corner he be done

    编辑:添加了 lemmaz 的示例,因为你提到了它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-10
      • 2018-10-29
      • 1970-01-01
      • 2019-12-31
      • 2022-09-30
      • 2011-10-12
      相关资源
      最近更新 更多