社交媒体文本分析的全能NLP工具集
TweetNLP是一个专注于社交媒体分析的Python库,为Twitter等平台提供全面的文本分析功能。该库集成了多项先进的自然语言处理技术,包括情感分析、表情预测、命名实体识别等。TweetNLP还支持主题分类、讽刺检测、仇恨言论识别和情感识别等多种任务,为社交媒体研究和应用开发提供了强大而灵活的工具集。
TweetNLP for all the NLP enthusiasts working on Twitter and social media!
The python library tweetnlp
provides a collection of useful tools to analyze/understand tweets such as sentiment analysis,
emoji prediction, and named-entity recognition, powered by state-of-the-art language modeling specialized on social media.
News (December 2022): We presented a TweetNLP demo paper ("TweetNLP: Cutting-Edge Natural Language Processing for Social Media"), at EMNLP 2022. The final version can be found here.
TweetNLP Hugging Face page All the main TweetNLP models can be found here on Hugging Face.
Resources:
Table of Contents:
Install TweetNLP via pip on your console.
pip install tweetnlp
In this section, you will learn how to get the models and datasets with tweetnlp
.
The models follow huggingface model and the datasets are in the format of huggingface datasets.
Easy introductions of huggingface models and datasets should be found at huggingface webpage, so
please check them if you are new to huggingface.
The classification module consists of six different tasks (Topic Classification, Sentiment Analysis, Irony Detection, Hate Speech Detection, Offensive Language Detection, Emoji Prediction, and Emotion Analysis).
In each example, the model is instantiated by tweetnlp.load_model("task-name")
, and run the prediction by passing a text or a list of texts as argument to the corresponding function.
import tweetnlp # MULTI-LABEL MODEL model = tweetnlp.load_model('topic_classification') # Or `model = tweetnlp.TopicClassification()` model.topic("Jacob Collier is a Grammy-awarded English artist from London.") # Or `model.predict` >>> {'label': ['celebrity_&_pop_culture', 'music']} # Note: the probability of the multi-label model is the output of sigmoid function on binary prediction whether each topic is positive or negative. model.topic("Jacob Collier is a Grammy-awarded English artist from London.", return_probability=True) >>> {'label': ['celebrity_&_pop_culture', 'music'], 'probability': {'arts_&_culture': 0.037371691316366196, 'business_&_entrepreneurs': 0.010188567452132702, 'celebrity_&_pop_culture': 0.92448890209198, 'diaries_&_daily_life': 0.03425711765885353, 'family': 0.00796138122677803, 'fashion_&_style': 0.020642118528485298, 'film_tv_&_video': 0.08062587678432465, 'fitness_&_health': 0.006343095097690821, 'food_&_dining': 0.0042883665300905704, 'gaming': 0.004327300935983658, 'learning_&_educational': 0.010652057826519012, 'music': 0.8291937112808228, 'news_&_social_concern': 0.24688217043876648, 'other_hobbies': 0.020671198144555092, 'relationships': 0.020371075719594955, 'science_&_technology': 0.0170074962079525, 'sports': 0.014291072264313698, 'travel_&_adventure': 0.010423899628221989, 'youth_&_student_life': 0.008605164475739002}} # SINGLE-LABEL MODEL model = tweetnlp.load_model('topic_classification', multi_label=False) # Or `model = tweetnlp.TopicClassification(multi_label=False)` model.topic("Jacob Collier is a Grammy-awarded English artist from London.") >>> {'label': 'pop_culture'} # NOTE: the probability of the sinlge-label model the softmax over the label. model.topic("Jacob Collier is a Grammy-awarded English artist from London.", return_probability=True) >>> {'label': 'pop_culture', 'probability': {'arts_&_culture': 9.20625461731106e-05, 'business_&_entrepreneurs': 6.916998972883448e-05, 'pop_culture': 0.9995898604393005, 'daily_life': 0.00011083036952186376, 'sports_&_gaming': 8.668467489769682e-05, 'science_&_technology': 5.152115045348182e-05}} # GET DATASET dataset_multi_label, label2id_multi_label = tweetnlp.load_dataset('topic_classification') dataset_single_label, label2id_single_label = tweetnlp.load_dataset('topic_classification', multi_label=False)
import tweetnlp # ENGLISH MODEL model = tweetnlp.load_model('sentiment') # Or `model = tweetnlp.Sentiment()` model.sentiment("Yes, including Medicare and social security saving👍") # Or `model.predict` >>> {'label': 'positive'} model.sentiment("Yes, including Medicare and social security saving👍", return_probability=True) >>> {'label': 'positive', 'probability': {'negative': 0.004584966693073511, 'neutral': 0.19360853731632233, 'positive': 0.8018065094947815}} # MULTILINGUAL MODEL model = tweetnlp.load_model('sentiment', multilingual=True) # Or `model = tweetnlp.Sentiment(multilingual=True)` model.sentiment("天気が良いとやっぱり気持ち良いなあ✨") >>> {'label': 'positive'} model.sentiment("天気が良いとやっぱり気持ち良いなあ✨", return_probability=True) >>> {'label': 'positive', 'probability': {'negative': 0.028369612991809845, 'neutral': 0.08128828555345535, 'positive': 0.8903420567512512}} # GET DATASET (ENGLISH) dataset, label2id = tweetnlp.load_dataset('sentiment') # GET DATASET (MULTILINGUAL) for l in ['all', 'arabic', 'english', 'french', 'german', 'hindi', 'italian', 'portuguese', 'spanish']: dataset_multilingual, label2id_multilingual = tweetnlp.load_dataset('sentiment', multilingual=True, task_language=l)
import tweetnlp # MODEL model = tweetnlp.load_model('irony') # Or `model = tweetnlp.Irony()` model.irony('If you wanna look like a badass, have drama on social media') # Or `model.predict` >>> {'label': 'irony'} model.irony('If you wanna look like a badass, have drama on social media', return_probability=True) >>> {'label': 'irony', 'probability': {'non_irony': 0.08390884101390839, 'irony': 0.9160911440849304}} # GET DATASET dataset, label2id = tweetnlp.load_dataset('irony')
import tweetnlp # MODEL model = tweetnlp.load_model('hate') # Or `model = tweetnlp.Hate()` model.hate('Whoever just unfollowed me you a bitch') # Or `model.predict` >>> {'label': 'not-hate'} model.hate('Whoever just unfollowed me you a bitch', return_probability=True) >>> {'label': 'non-hate', 'probability': {'non-hate': 0.7263831496238708, 'hate': 0.27361682057380676}} # GET DATASET dataset, label2id = tweetnlp.load_dataset('hate')
import tweetnlp # MODEL model = tweetnlp.load_model('offensive') # Or `model = tweetnlp.Offensive()` model.offensive("All two of them taste like ass.") # Or `model.predict` >>> {'label': 'offensive'} model.offensive("All two of them taste like ass.", return_probability=True) >>> {'label': 'offensive', 'probability': {'non-offensive': 0.16420328617095947, 'offensive': 0.8357967734336853}} # GET DATASET dataset, label2id = tweetnlp.load_dataset('offensive')
import tweetnlp # MODEL model = tweetnlp.load_model('emoji') # Or `model = tweetnlp.Emoji()` model.emoji('Beautiful sunset last night from the pontoon @TupperLakeNY') # Or `model.predict` >>> {'label': '😊'} model.emoji('Beautiful sunset last night from the pontoon @TupperLakeNY', return_probability=True) >>> {'label': '📷', 'probability': {'❤': 0.13197319209575653, '😍': 0.11246423423290253, '😂': 0.008415069431066513, '💕': 0.04842926934361458, '🔥': 0.014528146013617516, '😊': 0.1509675830602646, '😎': 0.08625403046607971, '✨': 0.01616635173559189, '💙': 0.07396604865789413, '😘': 0.03033279813826084, '📷': 0.16525287926197052, '🇺🇸': 0.020336611196398735, '☀': 0.00799981877207756, '💜': 0.016111424192786217, '😉': 0.012984540313482285, '💯': 0.012557178735733032, '😁': 0.031386848539114, '🎄': 0.006829539313912392, '📸': 0.04188741743564606, '😜': 0.011156936176121235}} # GET DATASET dataset, label2id = tweetnlp.load_dataset('emoji')
import tweetnlp # MULTI-LABEL MODEL model = tweetnlp.load_model('emotion') # Or `model = tweetnlp.Emotion()` model.emotion('I love swimming for the same reason I love meditating...the feeling of weightlessness.') # Or `model.predict` >>> {'label': 'joy'} # Note: the probability of the multi-label model is the output of sigmoid function on binary prediction whether each topic is positive or negative. model.emotion('I love swimming for the same reason I love meditating...the feeling of weightlessness.', return_probability=True) >>> {'label': 'joy', 'probability': {'anger': 0.00025800734874792397, 'anticipation': 0.0005329723935574293, 'disgust': 0.00026112011983059347, 'fear': 0.00027552215033210814, 'joy': 0.7721399068832397, 'love': 0.1806265264749527, 'optimism': 0.04208092764019966, 'pessimism': 0.00025325192837044597, 'sadness': 0.0006160663324408233, 'surprise': 0.0005619609728455544, 'trust': 0.002393839880824089}} # SINGLE-LABEL MODEL model = tweetnlp.load_model('emotion') # Or `model = tweetnlp.Emotion()` model.emotion('I love swimming for the same reason I love meditating...the feeling of weightlessness.') # Or `model.predict` >>> {'label': 'joy'} # NOTE: the probability of the
AI数字人视频创作平台
Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。
一站式AI创作平台
提供 AI 驱动的图片、视频生成及数字人等功能,助力创意创作
AI办公助手,复杂任务高效处理
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!
AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
AI小说写作助手,一站式润色、改写、扩写
蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。
全能AI智能助手,随时解答生活与工作的多样问题
问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。
实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。
最新AI工具、AI资讯
独家AI资源、AI项目落地
微信扫一扫关注公众号