SinglepassTextCluster, an TextCluster tools based on Singlepass cluster algorithm that use tfidf vector and doc2vec,which can be used for individual real-time corpus cluster task。基于single-pass算法思想的自动文本聚类小组件,内置tfidf和doc2vec两种文本向量方法,可自动输出聚类数目、类簇文档集合和簇类大小,用于自有实时数据的聚类任务。

Overview

项目的背景

SinglepassTextCluster, an TextCluster tool based on Singlepass cluster algorithm that use tfidf vector and doc2vec,which can be used for individual real-time corpus cluster task。基于single-pass算法思想的自动文本聚类小组件,内置tfidf和doc2vec两种文本向量方法,可自动输出聚类数目、类簇文档集合和簇类大小,用于自有实时数据的聚类任务。

项目的由来

实时热点话题、事件的发现,是针对实时信息流的一个典型应用场,如如HistoryHotEvent项目。地址:https://github.com/liuhuanyong/HistoryHotEventBase 。 其中包括了从2004年至2019年共16年的每日热点事件项目(004年至今共16年的历时热点标题数据库)。如何高效、快速地从大规模实时文本数据中发现具有代表性的新闻标题,并根据时间顺序挖掘出热点话题或事件的演化脉络具有十分重要的现实意义。 在热点挖掘这个方向上,笔者主要已经进行了若干项目的探索,并从这些项目中,可以总结出一个热点事件生成和演化脉络的挖掘,可以分成四个步骤:
1、面向实时文本流的文本获取。可以针对特定的主题词过滤的方式进行文本语料获取(参考EventMonitor项目,地址:https://github.com/liuhuanyong/EventMonitor ), 也可以以无过滤的方式获取实时的文本数据流,通过步骤2、3进一步得到特定主题的文本集合。
2、面向实时文本流的文本聚类。目标是将众多个文本进行文本聚类,包括文本的去重,聚类成不同的文本主题(粗分类),如将偷税、漏税文本事件聚合在一起。(话题聚类、文本聚类)。
3、聚类文本中的文本主题进行事件细分。针对每一类话题,进一步细分为不同的事件,形成不同主题下的事件,如A偷税漏税、B偷税漏税。(话题事件切分,参考TopicCluster项目。地址:https://github.com/liuhuanyong/TopicCluster )。
4、对细分的事件进行故事里程碑划分。借助时间信息,设定时间窗口,将同一个事件进一步划分成若干个时间事件切片,并挖掘出该事件切片中的代表性事件名称。(事件重要性计算,参考:ImportantEventExtractor项目。地址:https://github.com/liuhuanyong/ImportantEventExtractor )。
5、子事件演化脉络识别。对识别好的代表性事件名称,通过事件演化的特征(方向性特征、时间先后顺序特征、语义转移特征),构建事件演化脉络链。(事件演化脉络识别) 。

目前,关于步骤4和5目前还没有对应的项目,因此,为了填补这一空白,本项目选择步骤4,以Single-Pass算法的实现为例,进行实践说明:
Single-Pass算法又称单通道法或单遍法,是流式数据聚类的增量式方法,算法的时间效率高,适合对流数据进行挖掘,而。对于依次到达的文本数据流,该方法按输入顺序每次处理一个数据,依据当前数据与已有类的匹配度大小,将该数据判为已有类或者创建一个新的数据类,实现流式数据的增量和动态聚类。

项目的构成

1、data:待处理文本,如train.txt。
2、model: token_vector.bin,预先训练好的字向量,可用于文本的快速向量化。
3、result: 最终聚类结果文件,文件以json格式保存,记录聚类结果id、类簇中文本数量、类簇文本集合信息。
4、cluster_demo.py:聚类主控脚本,在该脚本中可直接指定聚类阈值,聚类的方法和聚类输入、输出文本路径。 5、cluster_doc2vec.py:基于doc2vec的主控聚类接口。
6、cluster_tfidf.py:基于tfidf的主控聚类接口。
7、singlepass_cluster_tfidf.py:基于tfidf的single-pass聚类算法实现细节。
8、singlepass_cluster_doc2vec.py:基于doc2vec的single-pass聚类算法实现细节。

项目的运行效果

1、项目运行方式:python cluster_demo.py 2、处理输入文本:train.txt,其中选择了1000条汽车需求评论语料,每条为1行,内容如下:

"""
但在一个周一晚上,州监管机构还是要求他们停止所有测试
问题是持久发展,需要市场投融资这个循环
所以买车前需要试驾
五菱荣光V(参数|询价),现在跑了30000多公里了,需要做哪些常规保养
总成3000,应该需要换码,我的灯还没到,等到了换完我上作业
建议在车内保险丝盒里面找一下,看位置图
车辆还有一年多的保修期,现在需要处理吗
现在根据修理店建议,我已经换了燃油泵总成,燃油压力调阀,问题依旧
个人建议质保期内还是在4S店保养吧
房车必须要足够大,才能住得舒服,因此房车的拓展应该成为房车的主流

"""

3、参数设置。使用doc2vec向量化方法,theta选择0.85。
4、聚类运行结果: cluster_doc2vec.json,共得到779个聚类结果,示例如下:

"""
{"cluster_id": 77, "cluster_nums": 5, "cluster_docs": [{"doc_id": 1, "doc_content": "那时候,冬天停车必须防水,根本没有防冻液这一说"}, {"doc_id": 2, "doc_content": "这两款比较的话,建议入手瑞风s3"}, {"doc_id": 3, "doc_content": "这里我们建议,首先将这几款车型上市的时间进行对比"}, {"doc_id": 4, "doc_content": "这东西,必须自己试驾"}, {"doc_id": 5, "doc_content": "希望大家可以透过这篇文章了解一下,轮胎的寿命…"}]}

"""

项目的总结

1、针对用户自有实时文本数据,利用聚类方法进行自动的文本聚类,得到聚类主题以及聚类的相关文档,可以为数据集文本的分析提供较好的帮助。基于single-pass算法思想的自动文本聚类小组件,可以直接使用。
2、singlepass聚类算法是一个简单、快速的聚类算法,其核心在于文档向量化方法以及聚类阈值,本工具内置tfidf和doc2vec两种文本向量方法,阈值可作为超参供用户指定输入。
3、文档向量化方法,有其他的更好的建模方法,如LDA聚类方法、bert向量化、word2vec向量化方法,大家可以在向量化阶段根据实际需求自动地进行向量化模块替换。
4、singlepass聚类方法对输入数据的顺序、阈值敏感,同一份数据,不同的输入顺序,不同的阈值,会得到不同的聚类结果。
5、singlepass聚类方法与输入数据的规模敏感,随着簇规模的增加,其计算量会越来越大(新文本要对所有簇中心进行比对),因此针对大的数据,需要设计高效的选型,如mapreduce或者根据某些特征过滤部分类簇,再进行相识度计算,减少计算量。
6、在处理具有时间序列信息的聚类任务(如实时热点挖掘)中,单独使用文本语义相似度的方法进行聚类是不够的,还需要考虑时间因素,因此可以在聚类的过程中设置时间聚类的阈值(一个新的超参), 在么每个聚类中心加入时间片段参数(记录该文簇中文档的第一个时间以及最后一个时间),如果新加的文本时间大于设定的时间,则不再加入该簇。
7、具体聚类的效果还与输入语料文本情况有关,不同的语料在同一个算法下,可能得出不同的聚类效果。

关于作者

刘焕勇,liuhuanyong,现任360人工智能研究院算法专家,前中科院软件所工程师,主要研究方向为知识图谱、事件图谱在实际业务中的落地应用。 得语言者得天下,得语言资源者,分得天下,得语言逻辑者,争得天下。
1、个人主页:https://liuhuanyong.github.io
2、个人博客:https://blog.csdn.net/lhy2014/
3、个人公众号:老刘说NLP
欢迎对自然语言处理、知识图谱、事件图谱理论技术、技术实践等落地应用的朋友一同交流。

Owner
liuhuanyong
the man who understand languages get the whole world
liuhuanyong
Source code for CsiNet and CRNet using Fully Connected Layer-Shared feedback architecture.

FCS-applications Source code for CsiNet and CRNet using the Fully Connected Layer-Shared feedback architecture. Introduction This repository contains

Boyuan Zhang 4 Oct 07, 2022
A Python 3.6+ package to run .many files, where many programs written in many languages may exist in one file.

RunMany Intro | Installation | VSCode Extension | Usage | Syntax | Settings | About A tool to run many programs written in many languages from one fil

6 May 22, 2022
Perform sentiment analysis on textual data that people generally post on websites like social networks and movie review sites.

Sentiment Analyzer The goal of this project is to perform sentiment analysis on textual data that people generally post on websites like social networ

Madhusudan.C.S 53 Mar 01, 2022
Sapiens is a human antibody language model based on BERT.

Sapiens: Human antibody language model ____ _ / ___| __ _ _ __ (_) ___ _ __ ___ \___ \ / _` | '_ \| |/ _ \ '

Merck Sharp & Dohme Corp. a subsidiary of Merck & Co., Inc. 13 Nov 20, 2022
تولید اسم های رندوم فینگیلیش

karafs کرفس تولید اسم های رندوم فینگیلیش installation ➜ pip install karafs usage دو زبانه ➜ karafs -n 10 توت فرنگی بی ناموس toot farangi-ye bi_namoos

Vaheed NÆINI (9E) 36 Nov 24, 2022
TruthfulQA: Measuring How Models Imitate Human Falsehoods

TruthfulQA: Measuring How Models Imitate Human Falsehoods

69 Dec 25, 2022
iSTFTNet : Fast and Lightweight Mel-spectrogram Vocoder Incorporating Inverse Short-time Fourier Transform

iSTFTNet : Fast and Lightweight Mel-spectrogram Vocoder Incorporating Inverse Short-time Fourier Transform This repo try to implement iSTFTNet : Fast

Rishikesh (ऋषिकेश) 126 Jan 02, 2023
KLUE-baseline contains the baseline code for the Korean Language Understanding Evaluation (KLUE) benchmark.

KLUE Baseline Korean(한국어) KLUE-baseline contains the baseline code for the Korean Language Understanding Evaluation (KLUE) benchmark. See our paper fo

74 Dec 13, 2022
Neural network models for joint POS tagging and dependency parsing (CoNLL 2017-2018)

Neural Network Models for Joint POS Tagging and Dependency Parsing Implementations of joint models for POS tagging and dependency parsing, as describe

Dat Quoc Nguyen 152 Sep 02, 2022
Develop open-source Python Arabic NLP libraries that the Arab world will easily use in all Natural Language Processing applications

Develop open-source Python Arabic NLP libraries that the Arab world will easily use in all Natural Language Processing applications

BADER ALABDAN 2 Oct 22, 2022
Chinese NER(Named Entity Recognition) using BERT(Softmax, CRF, Span)

Chinese NER(Named Entity Recognition) using BERT(Softmax, CRF, Span)

Weitang Liu 1.6k Jan 03, 2023
Web mining module for Python, with tools for scraping, natural language processing, machine learning, network analysis and visualization.

Pattern Pattern is a web mining module for Python. It has tools for: Data Mining: web services (Google, Twitter, Wikipedia), web crawler, HTML DOM par

Computational Linguistics Research Group 8.4k Dec 30, 2022
Official code for Spoken ObjectNet: A Bias-Controlled Spoken Caption Dataset

Official code for our Interspeech 2021 - Spoken ObjectNet: A Bias-Controlled Spoken Caption Dataset [1]*. Visually-grounded spoken language datasets c

Ian Palmer 3 Jan 26, 2022
A library that integrates huggingface transformers with the world of fastai, giving fastai devs everything they need to train, evaluate, and deploy transformer specific models.

blurr A library that integrates huggingface transformers with version 2 of the fastai framework Install You can now pip install blurr via pip install

ohmeow 253 Dec 31, 2022
Final Project for the Intel AI Readiness Boot Camp NLP (Jan)

NLP Boot Camp (Jan) Synopsis Full Name: Prameya Mohanty Name of your School: Delhi Public School, Rourkela Class: VIII Title of the Project: iTransect

TheCodingHub 1 Feb 01, 2022
PyTorch Language Model for 1-Billion Word (LM1B / GBW) Dataset

PyTorch Large-Scale Language Model A Large-Scale PyTorch Language Model trained on the 1-Billion Word (LM1B) / (GBW) dataset Latest Results 39.98 Perp

Ryan Spring 114 Nov 04, 2022
I can help you convert your images to pdf file.

IMAGE TO PDF CONVERTER BOT Configs TOKEN - Get bot token from @BotFather API_ID - From my.telegram.org API_HASH - From my.telegram.org Deploy to Herok

MADUSHANKA 10 Dec 14, 2022
👄 The most accurate natural language detection library for Python, suitable for long and short text alike

1. What does this library do? Its task is simple: It tells you which language some provided textual data is written in. This is very useful as a prepr

Peter M. Stahl 334 Dec 30, 2022
This project is part of Eleuther AI's quest to create a massive repository of high quality text data for training language models.

This project is part of Eleuther AI's quest to create a massive repository of high quality text data for training language models.

EleutherAI 42 Dec 13, 2022