machine-learning - 清洗 NLP 任务的文本数据

标签 machine-learning text nlp chatbot data-cleaning

今天早上,我一直在尝试在康奈尔电影对话语料库数据集上训练聊天机器人,但在清理文本数据以输入我的算法时遇到问题。 这是文本文件的片段

L1045 +++$+++ u0 +++$+++ m0 +++$+++ BIANCA +++$+++ They do not!
L1044 +++$+++ u2 +++$+++ m0 +++$+++ CAMERON +++$+++ They do to!
L985 +++$+++ u0 +++$+++ m0 +++$+++ BIANCA +++$+++ I hope so.
L984 +++$+++ u2 +++$+++ m0 +++$+++ CAMERON +++$+++ She okay?
L925 +++$+++ u0 +++$+++ m0 +++$+++ BIANCA +++$+++ Let's go.

L924+++$+++ u2+++$+++ m0+++$+++ 卡梅伦+++$+++ 哇 我只对每句话最后部分的对话感兴趣。 我怎样才能清理这个文件并使其成为 csv 文档?

数据集链接 http://www.cs.cornell.edu/~cristian/Cornell_Movie-Dialogs_Corpus.html

最佳答案

将所有行作为字符串进行迭代。

假设您有:

str = "+++$+++ u0 +++$+++ m0 +++$+++ BIANCA +++$+++ They do not!"

你想输出“他们不!”

喜欢:

str.split("+++$+++ ")[-1]

这将为您提供所需的输出。一旦您获得了所需的字符串输出,请将它们逐行写入您的 .csv 文件中。

希望这有帮助。

关于machine-learning - 清洗 NLP 任务的文本数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50431776/

相关文章:

r - trainControl 中的 p 参数

scala - Apache 弗林克 : changing state parameters at runtime from outside

machine-learning - 我们如何在数据集上使用无监督学习技术,然后标记集群?

jquery - 根据 H4 标签中包含的特定文本隐藏 div

python - 如何计算句子中的单词数,忽略数字、标点符号和空格?

python - NLTK CFG 多个单词语法

python - 使用sklearn计算仅给定单词列表的tf-idf权重

cocoa - 从 NSSegmentedControl 到标签

python - 对新文档进行分类 - 随机森林、词袋

tensorflow - BERT + 自定义层训练性能随着时代的推移而下降