Common Crawl data-based Chinese corpus acquisition method and system

By using technologies such as regular expressions, Beautiful Soup, blacklist filtering and hashing algorithms on Common Crawl data, the problem of noise and low-quality data in the acquisition of Chinese corpus has been solved, and high-quality and balanced Chinese corpus acquisition has been achieved, improving improve the accuracy and efficiency of data processing.

CN118535792APending Publication Date: 2024-08-23SHENZHEN INST OF ADVANCED TECH CHINESE ACAD OF SCI

Patent Information

Application Number
CN202410457590.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-16
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

It is difficult to obtain high-quality and balanced Chinese corpus with existing technology. Especially in Chinese scenarios, high-quality data sets are difficult to obtain and contain a lot of noise or low-quality content, which affects the performance of large-scale language models.

Method used

Using a method based on Common Crawl data, we use regular expressions and Beautiful Soup to extract Chinese text from HTML pages, use network blacklists to filter spam, use hash algorithms to remove duplicates, and use text models to perform quality screening to ensure the quality of the data. Quality and variety.

Benefits of technology

It achieves efficient processing and analysis of web page data, extracts valuable Chinese text information, improves the accuracy and efficiency of data processing, provides a reliable data foundation for subsequent text analysis and applications, and ensures the diversity of data sets. and balance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535792A
    Figure CN118535792A
Patent Text Reader

Abstract

The invention discloses a Chinese corpus obtaining method and system based on Common Crawl data. The method comprises the steps that webpage data and texts in an HTML page are extracted from WARC original webpage data of a Common Crawl database through a regular expression and Beauty Soup; filtering junk information from the text by using the constructed network blacklist, and merging the data according to the url in each piece of data in the text after filtering; and performing duplicate removal on the merged texts by utilizing a Hash algorithm, and performing quality screening on the Chinese texts through a text model after duplicate removal. According to the method, balanced and high-quality Chinese corpora can be obtained. The processing mode not only improves the accuracy and efficiency of data processing, but also provides a reliable data basis for subsequent text analysis and application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention proposes a Chinese corpus acquisition method and system based on Common Crawl data, belonging to the technical field of artificial intelligence. Background Art

[0002] In recent years, with the development of deep learning and neural network technology, researchers have begun to try to design more complex and powerful language models to improve the ability of computers to process natural language. Traditional natural language processing technology based on rules and statistical methods has limitations in the face of language complexity and semantic understanding, so more intelligent and flexible models are needed to solve these problems. Large language models (LLMs) refer to natural language processing models with a large number of parameters and complex structures. They are usually based on deep learning technology and can learn and understand the semantics and grammatical rules of natural language texts, and show strong performance in various tasks and applications. Large language models have received widespread attention and research in recent years. Some famous examples include OpenAI's GPT series (such as GPT-2, GPT-3) and Google's BERT model. Due to its importance and wide application in the field of natural language processing, large language models are also considered one of the important milestones in the development of artificial intelligence.

[0003] However, most of the world's leading open source large models are pre-trained and fine-tuned based on English datasets. To achieve high performance in Chinese scenarios, pre-training and fine-tuning on high-quality Chinese datasets are also indispensable. Although Chinese is the most widely spoken language in the world, high-quality and diverse Chinese datasets that can be used for training are not always easy to obtain due to the diversity and availability of data sources. Although there is a large amount of Chinese text data available on the Internet, much of it may be noise or low-quality content, such as colloquial text on social media, wrong or incomplete sentences, etc.

[0004] Therefore, effective screening and cleaning are required to ensure the quality of the data. At the same time, it is also important to ensure the balance of the corpus, which means that texts of different topics, types, and styles need to be covered to ensure that the model has a good understanding and generalization ability for various language features and uses. Summary of the invention

[0005] In order to solve the problem of low quality of Chinese texts obtained in the prior art, the present invention provides a method and system for obtaining Chinese corpus based on Common Crawl data, which can obtain balanced and high-quality Chinese corpus.

[0006] In order to solve the above technical problems, the technical solution adopted by the present invention is:

[0007] In a first aspect, the present invention provides a method for acquiring Chinese corpus based on Common Crawl data, comprising:

[0008] Use regular expressions and Beautiful Soup to extract web page data and text from HTML pages from the WARC raw web page data in the Common Crawl database;

[0009] Use the constructed network blacklist to filter spam from the text, and after filtering, merge the data according to the URL in each data in the text;

[0010] The merged text is deduplicated using a hash algorithm, and after deduplication, the Chinese text is quality screened using a text model.

[0011] As a further improvement of the present invention, the method of extracting Chinese text in HTML pages from WARC original web page data in Common Crawl database using regular expressions and Beautiful Soup includes:

[0012] Use regular expressions and corresponding libraries to preprocess the HTML pages of the WARC raw web page data in the Common Crawl database, including removing HTML tags, scripts, style sheets and parts that are irrelevant to the text content;

[0013] After preprocessing, import the Beautiful Soup library, use Beautiful Soup to parse the HTML page, find all tags by looping through them, and then call the extract() method to delete these tags and their contents respectively; get the processed HTML page content;

[0014] Use Beautiful Soup to parse the preprocessed HTML page, perform regular matching on the text of the extracted .txt attribute, find the Chinese text in it, and then calculate the proportion of Chinese text in the entire text. If this proportion is greater than a certain set threshold, it will be retained, otherwise the webpage will be ignored;

[0015] If the data after regular expression matching still contains a large number of blank characters or garbled content, regular expressions are continued to be used to remove this part of the content; finally, web page data containing Chinese text and removing front-end modified content and the extracted Chinese text are obtained;

[0016] Among them, HTML pages are stored in json format, and each json data retains the URL and data length information of the web page; the WARC format data in the Common Crawl data contains the content of the front-end page modified by CSS and Javascripts.

[0017] As a further improvement of the present invention, the method of filtering out junk information from the text by utilizing the constructed network blacklist includes:

[0018] A blacklist is built by visiting cybersecurity companies and organizations, open source blacklist projects, browser extensions and security tools, security forums and community resources on the Internet; if the URL in the header message of a JSON file of a web page hits the blacklist, the web page is filtered out;

[0019] The use of the constructed network blacklist to filter out junk information from the text refers to deleting repeated paragraphs in different web pages. Another purpose is to remove web page navigation bars, cookie warnings, and contact information.

[0020] As a further improvement of the present invention, the method of filtering out junk information from the text by utilizing the constructed network blacklist includes:

[0021] The data is split into fixed-size segments and saved in JSON format, where each entry corresponds to a crawled web page, and the paragraphs are normalized at the paragraph level of the web page;

[0022] Then, for the byte stream of each normalized text segment, use the MD5 algorithm to calculate its hash value, and store the MD5 hash value corresponding to each text segment;

[0023] For a new text paragraph, first calculate its MD5 hash value; then compare this hash value with the previously stored hash value: if the MD5 hash value of the new text paragraph already exists in the stored hash value, it will not be processed any further; if the hash value of the new text paragraph is new, it will be added to the stored hash value and continue to process the next text paragraph.

[0024] As a further improvement of the present invention, normalization processing is performed on the paragraphs at the paragraph level of the web page, including:

[0025] Make each paragraph all lowercase, replace numbers with placeholders, and remove all Unicode punctuation; convert each paragraph of text into a byte stream; this is achieved by encoding the text into a character encoding.

[0026] As a further improvement of the present invention, after deduplication, the Chinese text is quality screened by a text model, including:

[0027] Use the Kneser-Ney language model to tokenize each web page at the sentence level, and then score each paragraph. The lower the score, the closer it is to the target distribution and the higher the quality. According to the set threshold, the paragraphs with higher quality are retained.

[0028] As a further improvement of the present invention, after deduplication, the quality of the Chinese text is screened by the text model, and a sensitive word judgment step is also included, wherein the steps are:

[0029] Set up a list of sensitive words and divide the corresponding sensitive words into two levels. At the sentence level, if a sensitive word of level one is hit, the sentence will be deleted; if a sensitive word of level two is hit, set a threshold, and the sentence will be deleted if the number of hits exceeds this threshold.

[0030] In a second aspect, the present invention provides a Chinese corpus acquisition device based on Common Crawl data, comprising:

[0031] Extraction module, used to extract web page data and text in HTML pages from WARC raw web page data in Common Crawl database using regular expressions and Beautiful Soup;

[0032] The filtering and merging module is used to filter spam information from the text using the constructed network blacklist, and then merge the data according to the URL in each data in the text after filtering;

[0033] The deduplication and screening module is used to deduplicate the merged text using a hash algorithm, and then perform quality screening on the Chinese text through a text model after deduplication.

[0034] In a third aspect, the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the Chinese corpus acquisition method based on Common Crawl data when executing the computer program.

[0035] In a fourth aspect, the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for acquiring Chinese corpus based on Common Crawl data is implemented.

[0036] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions, wherein the computer instructions instruct a computer to execute the Chinese corpus acquisition method based on Common Crawl data.

[0037] The beneficial effects of the present invention compared with the prior art are as follows:

[0038] The whole process of the present invention forms a complete text processing chain from data extraction to deduplication and then to quality screening. By combining various technologies and tools such as regular expressions, Beautiful Soup, blacklist filtering, hash algorithms and text models, a large amount of web page data can be efficiently processed and analyzed to extract valuable Chinese text information. This processing method not only improves the accuracy and efficiency of data processing, but also provides a reliable data foundation for subsequent text analysis and application. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the embodiments of the present invention or the drawings of related technical solutions in the prior art are introduced below. It should be understood that the drawings introduced below are only for the convenience of clearly describing some embodiments of the technical solutions of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0040] Figure 1 A flow chart of a method for acquiring Chinese corpus based on Common Crawl data provided in an embodiment of the present invention;

[0041] Figure 2 This is a flowchart of extracting a Chinese data set according to an embodiment of the present invention;

[0042] Figure 3 The HTML page header message display of the embodiment of the present invention;

[0043] Figure 4 This is a deduplication flow chart of an embodiment of the present invention;

[0044] Figure 5 A Chinese corpus acquisition device based on Common Crawl data provided by the present invention;

[0045] Figure 6 A schematic diagram of an electronic device provided by the present invention. DETAILED DESCRIPTION

[0046] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and are not to be construed as limitations of the present invention. For the step numbers in the following embodiments, they are only provided for the convenience of explanation, and the order between the steps is not limited in any way, and the execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.

[0047] In the description of the present invention, unless otherwise clearly defined, terms such as setting, installing, connecting, etc. should be understood in a broad sense, and technicians in the relevant technical field can reasonably determine the specific meanings of the above terms in the present invention based on the specific content of the technical solution.

[0048] Glossary:

[0049] Beautiful Soup: is a Python library for parsing HTML and XML documents. It creates a parse tree to represent the structure of the document, making it easy to find, modify, and navigate HTML or XML documents. Beautiful Soup is not the fastest library, but it is simple to use and provides powerful features that can handle irregular and problematic HTML code. Using Beautiful Soup, you can easily extract specific tags, attributes, and text from HTML or XML. It also supports filters and search functions, which can locate elements in the document based on tag name, attributes, text content, etc.

[0050] Common Crawl data: is a massive, unstructured, multilingual web page dataset that covers more than 8 years of web crawler data. This dataset includes raw web page data (WARC), metadata (WAT), and text extraction (WET). It has a PB-level scale and can be obtained for free from Amazon S3. Common Crawl data is a very important data source in large model training. For example, in the training of GPT-3, Common Crawl data accounts for 60%. However, in the process of large model training, Common Crawl datasets are rarely used directly. Instead, they are first processed by filtering low-quality pages and removing page similarity to avoid overfitting.

[0051] In the field of artificial intelligence, large language models have been one of the research hotspots that have received much attention in recent years. These models have hundreds of millions or even trillions of parameters. Through pre-training and fine-tuning, they learn natural language representations on large corpora, thereby achieving excellent performance on various natural language processing tasks. However, the datasets required to build and train large language models are an important challenge. Obtaining high-quality Chinese corpora is a complex process that requires comprehensive consideration of data quality, copyright issues, domain requirements, and language characteristics. It may also require a lot of cleaning, screening, and labeling work. In order to obtain large-scale, high-quality Chinese corpora, researchers and developers have adopted a variety of methods:

[0052] Open source datasets: There are some open source Chinese corpora available, such as THUCTC (Tsinghua University Chinese Text Classification Corpus), LCQMC (Tencent Intelligent Conversation Dataset), etc. These datasets cover Chinese texts in different fields and topics and can be used to train and evaluate language models.

[0053] Cooperate with data providers: Some research institutions, enterprises or academic institutions may have large-scale Chinese corpora, and you can cooperate with them to obtain data. Through cooperation agreements or purchase methods, you can obtain Chinese corpora in specific fields or topics to meet the needs of model training.

[0054] Collect data by yourself: Another way to obtain Chinese corpus is to use crawler technology to crawl data from the Internet. Through search engines, websites, forums and other channels, a large amount of Chinese text data can be collected. They will first crawl the original web page data from the Internet, and then use some crawler frameworks (such as Beautifulsoup in Python) to parse the desired content from these raw data, and finally filter out meaningless navigation page information, spam, etc. from the web page based on these contents.

[0055] In terms of obtaining Chinese corpus, some existing methods have various problems. Crawling Internet data is an effective way to obtain information. However, this process is also accompanied by many challenges and problems. First, the quality of data on the Internet is uneven, and there may be errors, noise or false information, so effective data cleaning and filtering are needed. Secondly, the content on the Internet may be protected by copyright. Unauthorized crawling and use may involve infringement issues and bring legal risks. In addition, privacy issues are also a consideration. Data collection without user consent may violate privacy protection regulations. At the same time, some websites have taken anti-crawling measures to hinder the normal acquisition of data, and corresponding challenges need to be addressed. In addition, data on the Internet may come from different sources, and there are inconsistencies in data format, content and structure, which require data integration and normalization. In addition, the timeliness of Internet data is also a challenge, and data needs to be updated and synchronized regularly. Finally, crawling Internet data requires a lot of computing resources and bandwidth, especially for large-scale data sets, which requires corresponding hardware and manpower costs.

[0056] In summary, although Internet crawling is a convenient way to obtain data, in practice, we need to seriously deal with issues such as data quality, copyright, and privacy to ensure the legality, reliability, and security of the data. The technical solution proposed in this article uses the data from Common Crawl and defines a set of processing procedures to solve the problems of data crawling being restricted by anti-crawler when obtaining large-scale Chinese data sets, data acquisition requires a lot of computing resources and bandwidth, the diversity and balance of the obtained data sets cannot be guaranteed, and the data contains a lot of noise, errors, or low-quality text.

[0057] In order to solve the above two problems and obtain balanced, high-quality Chinese corpus, this technical solution proposes a method based on Common Craw's WARC data using hash algorithm and language model, and uses a series of filtering and deduplication algorithms on the original web page data (WARC) of Common Crawl to finally achieve the goal of the present invention. Due to the huge amount of data processed (tens to hundreds of TB), the tasks of the present invention are processed in parallel using Spark throughout the process.

[0058] like Figure 1 As shown, the present invention provides a Chinese corpus acquisition method based on Common Crawl data, comprising:

[0059] S100, uses regular expressions and Beautiful Soup to extract web page data and text from HTML pages from the WARC raw web page data in the Common Crawl database;

[0060] S200, using the constructed network blacklist to filter junk information from the text, and after filtering, merging the data according to the URL in each piece of data in the text;

[0061] S300 uses a hash algorithm to remove duplicates from the merged text, and after removing duplicates, the quality of the Chinese text is screened through a text model.

[0062] Based on the above method, it can be seen that in step S100, regular expression is a powerful text processing tool for matching, finding and replacing string patterns in text. It can be used to extract specific tags or attributes in HTML. Beautiful Soup is a Python library for parsing HTML and XML documents. It provides concise methods to navigate, search and modify tree structures. With Beautiful Soup, HTML documents can be parsed and elements and text of interest can be extracted.

[0063] Regular expressions and Beautiful Soup provide powerful parsing and extraction functions that can handle various complex HTML structures. Compared with simple string operations, they can extract the required data more accurately and reduce errors and noise. And Beautiful Soup provides an intuitive API that makes HTML parsing and extraction simple and convenient.

[0064] In step S200, the network blacklist is a list of known sources of junk information (such as spammers, malicious websites, etc.). By matching the entries in the blacklist, information from these sources can be filtered out. Data merging can merge related data together based on the URL information in the text. This helps to integrate scattered information into a complete page or document.

[0065] By filtering out junk information, the quality and purity of data can be significantly improved. Data merging helps to integrate scattered information into a meaningful structure, which is convenient for subsequent analysis and processing.

[0066] In step S300, the hash algorithm is an algorithm that maps a binary value of arbitrary length to a shorter binary value of fixed length. By calculating the hash value of the text and comparing whether the hash values ​​are the same, it is possible to quickly determine whether the text is repeated. The text model is a machine learning model for processing and analyzing text. By training the model, high-quality Chinese text can be identified and low-quality text can be filtered out. The specific text model can be selected as needed.

[0067] Among them, the hash algorithm can quickly identify duplicate texts and significantly improve data processing efficiency. The text model can evaluate the quality of texts according to preset standards to ensure that the selected texts meet the requirements.

[0068] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0069] In view of the above content, the present invention proposes a Chinese corpus acquisition method based on Common Crawl data for data extraction and filtering. The overall processing flow of the method is as follows: Figure 2 As shown. Mainly include:

[0070] First, the present invention uses the crawler package Beautiful Soup to parse Chinese data from the WARC original web page data of Common Crawl, and then uses the constructed network blacklist to filter out spam information from these texts. After that, the data is merged according to the network address (URL) in each data, and then the hash algorithm is used to deduplicate the merged text. Finally, the Chinese text is further filtered through the text model.

[0071] This technical solution will also be described from the above aspects, and the following is a detailed description:

[0072] In order to elaborate on the technical solution later, the present invention first introduces Common Crawl data. Common Crawl is a non-profit project that aims to build and provide a global text dataset on the Internet. The project regularly crawls public web pages, and organizes, stores and publicly releases the captured data, providing researchers, developers and communities with rich Internet data resources. This dataset has the characteristics of global coverage and large-scale data, covering web content in almost all regions and fields, with a total volume of hundreds of TB or even PB.

[0073] Therefore, the Common Crawl dataset provides researchers with an extremely valuable resource that can be used for various natural language processing, machine learning and data mining tasks, as well as in-depth analysis and understanding of Internet information. It has three data storage formats: WARC, WAT and WET. The processing flow of the present invention starts with data in WARC format. The WARC format is the format with the largest amount of data, because it is the raw data that has not been processed after crawling. As one of the main data formats of Common Crawl, its data content is very rich and may be very useful for making multimodal datasets. WARC data usually contains the original Hypertext Transfer Protocol (HTTP) response information, including response headers, status codes, content types, etc., as well as the actual content of the web page, such as CSS, JavaScript, etc., which modify the front-end code and displayed text or picture information. These data are used to store snapshots and metadata of web page crawls for subsequent data analysis, mining and retrieval. The existence of WARC data provides researchers with a rich resource that can be used for in-depth analysis and understanding of Internet information.

[0074] Among them, the steps of using Beautiful Soup and regular matching to extract text information are as follows:

[0075] The technical solution of this invention can effectively extract Chinese text from Hypertext Markup Language (HTML) pages by using regular expressions and Beautiful Soup. Regular expressions can be used to pre-process HTML pages to remove irrelevant content or tags, and Beautiful Soup can be used to parse HTML structures to extract the information desired by the invention. The HTML pages are stored in json format, and each json data will retain information such as the URL of the web page and the length of the data. Figure 3Below these header messages is the real original web page data, and for the subsequent deduplication and screening process, the data extracted by the present invention will also retain this part of information.

[0076] Because the WARC format data in Common Crawl data contains a lot of CSS, Javascripts and other content that decorates the front-end page, we can remove this part first. Specifically, use regular expressions and corresponding libraries to pre-process HTML pages. This includes removing HTML tags, scripts, style sheets and other parts that are not related to the text content. First, the present invention imports the Beautiful Soup library, then uses Beautiful Soup to parse the HTML page, and finds all the " <style>”和"<script>”等标签(例如可以调用find_all函数实现),接着分别调用extract()方法删除这些标签及其内容。最后,获取处理后的HTML页面内容。为了方便本发明后面继续处理网页,本发明将这一步处理完后的内容先放在迭代器中。

[0077] 作为示例,使用Beautiful Soup解析经过预处理的HTML页面。Beautiful Soup提供了方便的方法来遍历HTML结构,并提供了.text属性来获取元素中的文本内容。但是Common Crawl提供的数据包含了世界各地各种语言的数据,在许多情况下,一个HTML网页是不包含中文的,这时本发明就需要忽略这种类型的网页。

[0078] 作为示例,在这一部分本发明对提取到的.txt属性的文本进行正则匹配,找到其中的中文文本,然后计算中文文本所占整个文本的比例,如果这个比例大于某个设定的阈值,本发明就认为该网页包含中文文本,所以进行保留,反之则忽略该网页。处理完上面的任务之后,本发明检查数据发现,得到的数据还会包含大量空白字符或者乱码内容,因此本发明继续针对性的写了一系列正则表达式来去除这部分内容。

[0079] 构建网络黑名单过滤垃圾网站说明如下:

[0080] 经过上述的内容之后,本发明得到了两部分数据,一部分数据是包含中文文本并且去掉前端修饰内容的网页数据,另外一部分是从里面提取到的中文文本。虽然在自然语言中前者很少使用,但是这部分包含的数据内容非常丰富,对于制作多模态数据集非常有用,所以本发明将这部分数据也进行了保留。

[0081] 由于在互联网是有许多非法网页存在。如果本发明提取的数据包含这部分内容,那么无疑会大大降低数据集的质量,采用这种数据集训练出来的大模型肯定是不会被人们认可的。本发明通过访问互联网上网络安全公司和组织、开源黑名单项目、浏览器扩展和安全工具、安全论坛和社区等这些资源构建了一个黑名单。如果一条json文件中头消息里的url命中了这个黑名单,这个网页就会被过滤掉。本发明在真实的Common Crawl的数据上进行了实验,采用黑名单过滤之后,原来数据集的容量平均减少了27%。这说明本发明采用的黑名单是有效的,可以大大减少数据集中的非法信息。

[0082] 哈希算法实现重复文本去重的步骤说明如下:

[0083] 首先对哈希算法进行一个简单的介绍。哈希算法是一种将任意长度的输入数据映射为固定长度的输出数据的算法。哈希算法的核心思想是将输入数据通过一个确定性的过程转换为固定长度的哈希值,该哈希值通常用于表示原始数据。常见的哈希算法包括MD5(Message Digest Algorithm 5)、SHA-1(Secure Hash Algorithm 1)、SHA-256等。这些算法在各自的应用领域具有广泛的应用,例如数据完整性校验、密码学安全、数据唯一标识等。通常来讲越安全的算法,计算时的时间开销就越大,由于去重时对于安全性没有很强的考量,所以本发明本次去重使用了MD5这种计算相对简单的算法。这是一种基于分组的哈希算法,将输入数据划分为固定大小的块进行处理,MD5生成的哈希值长度为128位(16字节)

[0084] 去重的目的是删除不同网页中的重复段落,另外一个目的是去除了网页导航栏、cookie警告、联系信息等。

[0085] 首先本发明对数据分割成大小固定的片段,并以JSON格式保存,其中每个条目对应一个已爬取的网页。因为去重是在段落级别进行的,所以本发明对段落进行归一化处理。具体来说每个段落全部小写化,把数字用占位符替换,删除所有统一码Unicode标点符号。将每一段文本转换为字节流的形式。这可以通过将文本编码为UTF-8或其他字符编码来实现。接着对于每一段文本的字节流,使用MD5算法计算其哈希值。通常,编程语言和库提供了计算哈希值的函数或方法。将每一段文本对应的MD5哈希值存储起来。可以使用数据结构,如哈希表、集合或数据库来存储哈希值。

[0086] 作为示例,对于新的文本段落,首先计算其MD5哈希值。然后,将这个哈希值与之前存储的哈希值进行比较。如果新文本段落的MD5哈希值已经存在于存储的哈希值中,那么说明这个文本段落已经出现过,可以将其视为重复的,不再进行处理。如果新文本段落的哈希值是新的,则将其添加到已存储的哈希值中,并继续处理下一个文本段落。考虑到本发明的数据集只提取中文语料,相比全文本提取,过滤了海量的数据,所以本发明把片段划分为较小的1G。较小的内存还可以减少去重时内存的消耗。去重可以在每个划分的片段内进行,也可以在多个片段间进行,前者需要的计算资源少,后者需要的计算资源多,但是会删除更多的文档。

[0087] 鉴于中文数据集的特点以及本发明的计算资源有限,本发明去重只在每个片段内进行。通过本发明的实验统计,经过去重之后,1G大小的片段平均保留了53%。这一部分的流程图如图4所示。

[0088] 语言模型提高数据集质量步骤具体说明如下:

[0089] 到目前位置本发明已经完成了中文网页的过滤,数据的去重,初步的过滤筛选。然而,经历这些步骤并不意味着数据的质量就一定很好。所以本发明还需要对数据进行进一步的处理。

[0090] 作为示例,本发明参考了脸书(facebook)的fastText这篇论文对文本进行质量打分的方式,对本发明提取的中文数据进行了质量筛选。本发明直接使用了开源的Kneser-Ney语言模型,把每一个网页在句子层面做分词(tokenize),然后对于每一个自然段做一次打分,分数越低,与目标的分布越接近,质量越高。根据本发明设定的阈值,本发明只保留质量较高的那部分段落。但是采用语言模型过滤文本有时候会过滤掉本发明需要的信息,而且语言模型的好坏本身也会对处理结果产生重要影响,所以这一部分内容在实际应用中是可选的。具体方法是本发明制作了一个敏感词列表,对相应的敏感词分为了2级,在句子层面,如果命中了等级为一的敏感词,则删除该句子。如果命中的是敏感词第二级,则设置一个阈值,超过这个次数就删除这个句子。

[0091] 与现有技术相比,本发明的方法是针对中文数据而言的,具有特殊性。其次本发明使用了Common Crawl的WARC数据解决了自己爬取数据遭到反爬限制和需要消耗大量的计算资源和带宽的问题。使用WARC相比于使用WAT和WET,数据的完整性得到了保证,而且产生的一部分中间过程数据可以制作多模态数据集。最后获取的数据集多样性和平衡性是有保证的,同时还过滤了涉政和非法信息。

[0092] 本发明提出了一个在Common Crawl数据的基础上进行哈希去重和文本质量筛选的中文数据集获取方法,本发明制作了针对中文数据集的敏感词列表,这种方法在大规模的中文数据集获取方面发挥了作用,得到的中文数据是海量的和平衡的,具有典型性和代表性。

[0093] 本发明在Common Crawl的WARC数据上进行了充分的实验验证,结果显示,该技术方案不仅切实可行,而且表现出色。这一成果充分证明了本发明的有效性和可靠性,为后续的应用和推广奠定了坚实的基础。

[0094] 如图5所示,本发明第二个目的是提供一种基于Common Crawl数据的中文语料获取系统,包括:

[0095] 提取模块,用于使用正则表达式和Beautiful Soup从Common Crawl数据库的WARC原始网页数据中提取HTML页面中的网页数据和文本;

[0096] 过滤合并模块,用于利用构建的网络黑名单从文本中过滤垃圾信息,过滤之后根据文本中每条数据中的url对数据进行合并;

[0097] 去重筛选模块,用于利用哈希算法对合并后的文本进行去重,去重后通过文本模型对中文文本进行质量筛选。

[0098] 如图6所示,本发明实施例的第三个目的是提供一种电子设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现上述基于Common Crawl数据的中文语料获取方法。

[0099] 本发明实施例的第四个目的是提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述基于Common Crawl数据的中文语料获取方法。

[0100] 本发明实施例的第五个目的是提供一种计算机程序产品,所述计算机程序产品包括计算机指令,其特征在于,所述计算机指令指示计算机执行上述基于Common Crawl数据的中文语料获取方法。

[0101] 这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和 / 或方框图一个方框或多个方框中指定的功能。

[0102] 这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和 / 或方框图一个方框或多个方框中指定的功能的步骤。

[0103] 本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。

[0104] 本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和 / 或方框图来描述的。应理解可由计算机程序指令实现流程图和 / 或方框图中的每一流程和 / 或方框、以及流程图和 / 或方框图中的流程和 / 或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和 / 或方框图一个方框或多个方框中指定的功能的装置。

[0105] 显然,所描述的实施例仅仅是本发明的部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本发明保护的范围。

[0106] 最后应当说明的是:以上实施例仅用以说明本发明的技术方案而非对其限制,尽管参照上述实施例对本发明进行了详细的说明,所属领域的普通技术人员应当理解:依然可以对本发明的具体实施方式进行修改或者等同替换,而未脱离本发明精神和范围的任何修改或者等同替换,其均应涵盖在本发明的权利要求保护范围之内。< / style>

Claims

1. A Chinese corpus acquisition method based on Common Crawl data, It is characterized in that include: Use regular expressions and Beautiful Soup to extract web page data and text from HTML pages from the WARC raw web page data in the Common Crawl database; Use the constructed network blacklist to filter spam from the text, and after filtering, merge the data according to the URL in each data in the text; The merged text is deduplicated using a hash algorithm, and after deduplication, the Chinese text is quality screened using a text model.

2. According to the method for obtaining Chinese corpus based on Common Crawl data according to claim 1, It is characterized in that The method of using regular expressions and Beautiful Soup to extract Chinese text from HTML pages from WARC raw web page data in the Common Crawl database includes: Use regular expressions and corresponding libraries to preprocess the HTML pages of the WARC raw web page data in the Common Crawl database, including removing HTML tags, scripts, style sheets and parts that are irrelevant to the text content; After preprocessing, import the Beautiful Soup library, use Beautiful Soup to parse the HTML page, find all tags by looping through them, and then call the extract() method to delete these tags and their contents respectively; get the processed HTML page content; Use Beautiful Soup to parse the preprocessed HTML page, perform regular matching on the text of the extracted .txt attribute, find the Chinese text in it, and then calculate the proportion of Chinese text in the entire text. If this proportion is greater than a certain set threshold, it will be retained, otherwise the webpage will be ignored; If the data after regular expression matching still contains a large number of blank characters or garbled content, regular expressions are continued to be used to remove this part of the content; finally, web page data containing Chinese text and removing front-end modified content and the extracted Chinese text are obtained; Among them, HTML pages are stored in json format, and each json data retains the URL and data length information of the web page; the WARC format data in the Common Crawl data contains the content of the front-end page modified by CSS and Javascripts.

3. According to the method for obtaining Chinese corpus based on Common Crawl data as described in claim 1, It is characterized in that The network blacklist constructed by using the method described herein filters out junk information from the text, including: A blacklist is built by visiting cybersecurity companies and organizations, open source blacklist projects, browser extensions and security tools, security forums and community resources on the Internet; if the URL in the header message of a JSON file of a web page hits the blacklist, the web page is filtered out; The use of the constructed network blacklist to filter out junk information from the text refers to deleting repeated paragraphs in different web pages. Another purpose is to remove web page navigation bars, cookie warnings, and contact information.

4. According to the method for obtaining Chinese corpus based on Common Crawl data as described in claim 1, It is characterized in that The network blacklist constructed by using the method described herein filters out junk information from the text, including: The data is split into fixed-size segments and saved in JSON format, where each entry corresponds to a crawled web page, and the paragraphs are normalized at the paragraph level of the web page; Then, for the byte stream of each normalized text segment, use the MD5 algorithm to calculate its hash value, and store the MD5 hash value corresponding to each text segment; For a new text paragraph, first calculate its MD5 hash value; then compare this hash value with the previously stored hash value: if the MD5 hash value of the new text paragraph already exists in the stored hash value, it will not be processed any further; if the hash value of the new text paragraph is new, it will be added to the stored hash value and continue to process the next text paragraph.

5. According to the method for obtaining Chinese corpus based on Common Crawl data as described in claim 4, It is characterized in that Normalize paragraphs at the paragraph level of a web page, including: Make each paragraph all lowercase, replace numbers with placeholders, and remove all Unicode punctuation; convert each paragraph of text into a byte stream; this is achieved by encoding the text into a character encoding.

6. According to the method for obtaining Chinese corpus based on Common Crawl data as claimed in claim 1, It is characterized in that After deduplication, the Chinese text is screened for quality through the text model, including: Use the Kneser-Ney language model to tokenize each web page at the sentence level, and then score each paragraph. The lower the score, the closer it is to the target distribution and the higher the quality. According to the set threshold, the paragraphs with higher quality are retained.

7. According to the method for obtaining Chinese corpus based on Common Crawl data as described in claim 1, It is characterized in that After deduplication, the quality screening of Chinese texts through the text model also includes the sensitive word judgment step, which includes the following steps: Set up a list of sensitive words and divide the corresponding sensitive words into two levels. At the sentence level, if a sensitive word of level one is hit, the sentence will be deleted; if a sensitive word of level two is hit, set a threshold, and the sentence will be deleted if the number of hits exceeds this threshold.

8. A Chinese corpus acquisition device based on Common Crawl data, It is characterized in that include: Extraction module, used to extract web page data and text in HTML pages from WARC raw web page data in Common Crawl database using regular expressions and Beautiful Soup; The filtering and merging module is used to filter spam information from the text using the constructed network blacklist, and then merge the data according to the URL in each data in the text after filtering; The deduplication and screening module is used to deduplicate the merged text using a hash algorithm, and then perform quality screening on the Chinese text through a text model after deduplication.

9. An electronic device, It is characterized in that The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for acquiring Chinese corpus based on Common Crawl data as described in any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for acquiring Chinese corpus based on Common Crawl data according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Webpage data capturing and filtering method

    CN102567521A

  • Data acquisition system and data acquisition method

    CN107506502A

  • Data cleaning method, device, equipment and readable storage medium

    CN113722416A

  • Method, system and equipment for aligning bilingual text paragraphs in single webpage and medium

    CN116028741A

  • Network real-time hot topic mining analysis and public opinion extraction system

    CN117786249A

Cited By

  • Translation manuscript word number statistical method and device, computer equipment and storage medium

    CN119091449A

  • Method, device, computer equipment and storage medium for counting the number of words in a translation manuscript

    CN119091449B

  • An adaptive configurable general corpus production pipeline method and system

    CN123138582A