数据集:
Abirate/english_quotes
english_quotes 是从 goodreads quotes 中提取的所有名言的数据集。该数据集可用于多标签文本分类和文本生成。每个名言的内容都是用英语书写,并涉及自然语言处理等领域的数据集。
数据集中的文本为英语(en)。
数据集中一个典型实例的JSON格式示例:
{'author': 'Ralph Waldo Emerson',
 'quote': '“To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.”',
 'tags': ['accomplishment', 'be-yourself', 'conformity', 'individuality']}
 数据字段 我将数据集保持为一个数据块(train),以便后续通过使用hugging face数据集库的方法(如.train_test_split()方法),可以由用户对其进行洗牌和拆分。
我希望与HuggingFace社区分享我的数据集(通过网络爬取和其他清理处理创建),以便他们可以在NLP任务中使用,推动人工智能的进步。
数据来源数据的来源是 goodreads 网站:来源于 goodreads quotes 。
初始数据收集和规范化数据收集过程使用BeautifulSoup和Requests库进行网页爬取。在网页爬取后,对数据进行了轻微修改:删除所有带有"None"标签的名言,并从所有标签中删除"attributed-no-source"标签,因为该标签对名言的主题没有附加价值。
资源数据的制作者是谁?数据是由机器生成(使用网络爬取)并经过人工处理的。
下面,我提供了我创建的爬取数据的脚本(以及我进行的其他处理):
import requests
from bs4 import BeautifulSoup
import pandas as pd
import json
from collections import OrderedDict
page = requests.get('https://www.goodreads.com/quotes')
if page.status_code == 200:
    pageParsed = BeautifulSoup(page.content, 'html5lib')
    
# Define a function that retrieves information about each HTML quote code in a dictionary form.
def extract_data_quote(quote_html):
        quote = quote_html.find('div',{'class':'quoteText'}).get_text().strip().split('\n')[0]
        author = quote_html.find('span',{'class':'authorOrTitle'}).get_text().strip()
        if quote_html.find('div',{'class':'greyText smallText left'}) is not None:
            tags_list = [tag.get_text() for tag in quote_html.find('div',{'class':'greyText smallText left'}).find_all('a')]
            tags = list(OrderedDict.fromkeys(tags_list))
            if 'attributed-no-source' in tags:
                tags.remove('attributed-no-source')
        else:
            tags = None
        data = {'quote':quote, 'author':author, 'tags':tags}
        return data
# Define a function that retrieves all the quotes on a single page. 
def get_quotes_data(page_url):
    page = requests.get(page_url)
    if page.status_code == 200:
        pageParsed = BeautifulSoup(page.content, 'html5lib')
        quotes_html_page = pageParsed.find_all('div',{'class':'quoteDetails'})
        return [extract_data_quote(quote_html) for quote_html in quotes_html_page]
# Retrieve data from the first page.
data = get_quotes_data('https://www.goodreads.com/quotes')
# Retrieve data from all pages.
for i in range(2,101):
    print(i)
    url = f'https://www.goodreads.com/quotes?page={i}'
    data_current_page = get_quotes_data(url)
    if data_current_page is None:
        continue
    data = data + data_current_page
data_df = pd.DataFrame.from_dict(data)
for i, row in data_df.iterrows():
    if row['tags'] is None:
        data_df = data_df.drop(i)
# Produce the data in a JSON format.
data_df.to_json('C:/Users/Abir/Desktop/quotes.jsonl',orient="records", lines =True,force_ascii=False)
# Then I used the familiar process to push it to the Hugging Face hub.
 注释 注释是初始数据收集的一部分(请参见上述脚本)。
Abir ELTAIEF
授权信息本作品采用知识共享署名4.0国际许可协议(用于网络爬取的所有软件和库也可根据此知识共享署名许可协议提供)。
贡献感谢 @Abirate 添加了此数据集。