作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想标记包含多个表情符号的推文,并且它们不是空格分隔的。我都试过了 NLTK TweetTokenizer
和 Spacy
但他们无法标记表情符号肤色修饰符。这需要应用于庞大的数据集,因此性能可能是一个问题。有什么建议?
您可能需要使用 Firefox 或 Safari 来查看准确的色调表情符号,因为 Chrome 有时无法呈现它!
# NLTK
from nltk.tokenize.casual import TweetTokenizer
sentence = "I'm the most famous emoji 😂😂😂 but what about 👍 and 🚗👍🏼😂👍🏿"
t = TweetTokenizer()
print(t.tokenize(sentence))
# Output
["I'm", 'the', 'most', 'famous', 'emoji', '😂', '😂', '😂', 'but', 'what', 'about', '👍', 'and', '🚗', '👍', '🏼', '😂', '👍', '🏿']
和
# Spacy
import spacy
nlp = spacy.load("en_core_web_sm")
sentence = nlp("I'm the most famous emoji 😂😂😂 but what about 👍 and 🚗👍🏼😂👍🏿")
print([token.text for token in sentence])
Output
['I', "'m", 'the', 'most', 'famous', 'emoji', '😂', '😂', '😂', 'but', 'what', 'about', '👍', 'and', '🚗', '👍', '🏼', '😂', '👍', '🏿']
预期产出
["I'm", 'the', 'most', 'famous', 'emoji', '😂', '😂', '😂', 'but', 'what', 'about', '👍', 'and', '🚗', '👍🏼', '😂', '👍🏿']
最佳答案
您应该尝试使用 spacymoji .它是 spaCy 的扩展和管道组件,可以选择性地将组合表情符号(如肤色修饰符)合并为单个标记。
根据自述文件,您可以执行以下操作:
import spacy
from spacymoji import Emoji
nlp = spacy.load('en')
emoji = Emoji(nlp, merge_spans=True) # this is actually the default
nlp.add_pipe(emoji, first=True)
doc = nlp(...)
那应该这样做。
关于python-3.x - 使用表情符号肤色修饰符标记句子或推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64112225/
我想开发一个 Skype 机器人,它将用户名作为输入,并根据用户输入以相反的字符大小写表示hello username。简而言之,如果用户输入他的名字 james,我的机器人会回复他为 Hello J
我是一名优秀的程序员,十分优秀!