gpt4 book ai didi

python-3.x - 使用表情符号肤色修饰符标记句子或推文

转载 作者:行者123 更新时间:2023-12-03 21:46:01 26 4
gpt4 key购买 nike

我想标记包含多个表情符号的推文,并且它们不是空格分隔的。我都试过了 NLTK TweetTokenizerSpacy但他们无法标记表情符号肤色修饰符。这需要应用于庞大的数据集,因此性能可能是一个问题。有什么建议?
您可能需要使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com