대규모 단일 데이터 세트를 만들기 위해 크롤링, 정리 및 중간 웹 페이지를 입을 수있는 간단한 라이브러리. 이 라이브러리를 사용하면 GPT-2에 OpenAI에서 사용하는 데이터 세트보다 큰 데이터 세트를 만들 수 있어야합니다.
이 라이브러리는 Python 3을 사용합니다.
git clone https://github.com/chiphuyen/lazynlp.git
cd lazynlp
pip3 install -r requirements.txt
pip3 install .라이브러리를 제거하려면 다음을 사용하십시오.
pip3 uninstall lazynlp
사용할 수있는 몇 가지 주요 URL 덤프가 있습니다.
이것은 몇 달씩 Reddit에 대한 모든 제출물에 대한 링크입니다. 원시 덤프 및 프로세스를 다운로드하여 링크를 얻을 수 있습니다. 이 덤프 각각은 거대합니다 (100MB -1GB).
@jcpeterson은 여기에서 다운로드 할 수있는 3 개 이상의 카르마를 가진 중복 제거 된 링크 목록을 제공 할만 큼 친절합니다.
2015-06에서 2018-10 년 사이에 약 23m의 URL이 있으며, 그 중 약 40-60 %는 잘못된 URL입니다 (URL은 더 이상 존재하지 않거나 스크레이퍼 친화적이지 않음). 이는 이로부터 모든 좋은 URL을 다운로드하여 청소 한 후 약 10m 웹 페이지 또는 50GB의 순수한 텍스트가 있어야 함을 의미합니다.
Gutenberg 책에 모든 URL 목록을 다운로드 할 수 있습니다. 약 14GB의 순수한 텍스트로 변환하는 50K 서적이 있습니다.
lazynlp.get_us_gutenberg_links() 실행하여 동일한 목록을 얻을 수도 있습니다. 예를 들어, 모든 Gutenberg URL을 가져 와서 us_gutenberg.urls 파일에 저장하려면 다음 명령을 실행하십시오. 반나절이 걸릴 수 있습니다.
lazynlp.get_us_gutenberg_links('us_gutenberg.urls')
여기에서 모든 URL 목록을 호주 Gutenberg 책으로 다운로드 할 수 있습니다. 약 1GB의 순수한 텍스트로 변환하는 4K 책이 있습니다.
lazynlp.get_aus_gutenberg_links() 실행하여 동일한 목록을 얻을 수도 있습니다. 예를 들어, 모든 Gutenberg URL을 가져 와서 파일 aus_gutenberg.urls 에 저장하려면 :
lazynlp.get_aus_gutenberg_links('aus_gutenberg.urls')
여기에서 Wikipedia 덤프를 다운로드 할 수 있습니다.
동일한 URL을 여러 번 다운로드하고 싶지 않습니다. 모든 URL을 제거하는 데 도움이되는 두 가지 기능이 있습니다.
lazynlp.dedup_lines(files, outfold)
이 함수는 파일 목록을 가져옵니다 (각 파일에서 각 줄은 URL입니다). 중복 제거 된 모든 파일을 Outfold로 저장하십시오.
lazynlp.dedup_lines_from_new_file(original_files, new_file, outfile)
이 기능은 이전에 중복 된 모든 파일 (Original_Files)에 대해 새 파일을 제거 할 수 있습니다.
각 웹 페이지를 별도로 다운로드하려면 다음과 같이 전화하십시오.
lazynlp.download_page(link, context=None, timeout=None)
URL 목록이 포함 된 파일에서 다운로드하려면 다음으로 전화하십시오.
lazynlp.download_pages(link_file, folder, timeout=30, default_skip=True, extensions=[], domains=[])
"""
link_file:
file contains links to webpages to crawl. Each line contains one URL.
folder:
folder that you want to contain your downloaded pages.
timeout:
seconds to wait for a page to respond before abandoning it.
default_skip:
set to True if you want to automatically skip all URLs that contain domains and extensions that are known to be scraper-unfriendly or NSFW.
You can see the list of excluded domains at lazynlp/exclude_domains.txt.
You can see the list of excluded extensions at lazynlp/exclude_extensions.txt
You can also add your own domains and extensions to skip with domains and extensions and arguments.
In the folder:
Each URL is downloaded into a file, indexed by the order in which it is downloaded. The first line of each file is the URL. The rest is the textual content of the page.
index.urls contains all the URLs that have been successfully downloaded.
bad.urls contains the URLs that are bad.
connection.urls contains the URLs that haven't been downloaded because of connection issues.
non_ascii.urls contains the URLs that haven't been downloaded because of bad encoding issues.
empty.urls contains the URLs that have empty textual content.
"""
URL이 많으면 목록을 여러 파일로 나누고이 기능을 별도로 호출 할 수 있습니다. 40 개의 스크립트를 동시에 실행할 수있었습니다. 코드를 평행 할 수 있다고 생각합니다. 방금 이것이 더 쉽다는 것을 알았습니다.
모든 HTML 태그를 제거하고, UTF-8을 문자열로 디코딩하고, 외국 문자를 번역하고, 공백을 붕괴시키고, 인쇄 할 수없는 문자를 교체하고, Escape HTML 등을 사용할 수 있습니다.
대부분의 처리를 수행하려면 다음 기능을 호출 할 수도 있습니다.
lazynlp.clean_page(page)
이 라이브러리에서 lazynlp.download_pages() 함수는 크롤링 및 청소 부분을 모두 수행하므로 귀하가 가진 웹 페이지는 다음과 같은 순수한 텍스트입니다.
http://www.thecannabist.co/2017/03/02/jeff-sessions-russia-resign-democrats/74687/
Attorney general nominee Sen. Jeff Sessions, R-Ala., testifies on Capitol Hill in Washington on Jan. 10, 2017, in the first day of his confirmation hearing before the Senate Judiciary Committee. Top Democrats now say that because he misled the committee about his visits to Russia, he should resign. (Andrew Harnik, The Associated Press)
House Oversight and Government Reform Committee Chairman Jason Chaffetz, R-Utah, tweeted early Thursday that "AG Sessions should clarify his testimony and recuse himself."
Later, Sen. Rob Portman, R-Ohio, said in a statement, "Jeff Sessions is a former colleague and a friend, but I think it would be best for him and for the country to recuse himself from the DOJ Russia probe."
House Majority Leader Kevin McCarthy, R-Calif., also initially said during an appearance on MSNBC's "Morning Joe" that Sessions should bow out.
Asked whether Sessions should recuse himself in this situation, McCarthy replied "I think the trust of the American people -- you recuse yourself in these situations, yes."
McCarthy was pressed a second time about whether he was calling for Sessions to recuse himself and he confirmed that he believed the situation required a recusal.
"I think it would be easier from that standpoint, yes," McCarthy said.
But McCarthy later said his comment had been misinterpreted, telling Fox News' "Fox and Friends," "I'm not calling on him to recuse himself. I was asked on 'Morning Joe,' if he needs to recuse himself as going forward. As you just heard, Attorney General Sessions said he would recuse himself going forward -- appropriate, and that's all my answer was."
The comments from prominent Republicans follow revelations that Sessions met with the Russian ambassador during election season. Under oath in front of the Senate Judiciary Committee for his confirmation hearing in January, Sessions had said that he had not met with any Russian officials.
Senate Minority Leader Charles Schumer, D-N.Y., joined growing Democratic calls for Sessions to either resign or at least recuse himself from any investigations into Russia's meddling in U.S. elections.
"Attorney General Sessions cannot possibly lead an investigation into Russian interference in our elections or come anywhere near it. With these revelations, he may indeed become the subject of it," Schumer told reporters. "Better for the country if he resigns, but let's get an investigation going."
Because the Department of Justice should be above reproach, for the good of the country, the Attorney General should resign.
텍스트가 과도하게 표현되는 것을 피하려면 다른 페이지와 크게 겹치지 않는 페이지 만 포함하려고합니다.
특정 소스 파일로 대상 파일의 겹치는 양을 추정하려면이 기능을 사용하십시오.
lazynlp.estimate_overlap(source_files, target_files, gran='word', n=8, capacity=10000, error_rate=1e-5, header=0, interval=100000)
gran 토큰의 과립입니다 : 'char'또는 'word'레벨.
n 은 n- 그램입니다.
capacity 및 error_rate 는 BloomFilter에 사용됩니다.
header : 건너 뛰는 각 파일의 줄 수. 우리 형식에서 첫 번째 줄은 URL이기 때문입니다.
기존 BloomFilter와 대상 파일의 겹치는 양을 추정하려면이 기능을 사용하십시오.
lazynlp.estimate_overlap_bf(bf, target_file, gran='word', n=8, header=0)
파일 목록이 주어지면 정리 된 웹 페이지와 다른 파일과 겹치는 threshold 이상의 모든 파일을 필터링하려면이 기능을 사용하십시오.
lazynlp.filter_files(files, threshold=0.5, gran='word', n=8, capacity=100000000, error_rate=1e-7, header=0, interval=1000000)
복제 된 것으로 간주되는 모든 파일의 이름은 dupped_files.list 에 저장됩니다.
데이터 세트에 사용되는 모든 파일의 이름은 clean_files.list 에 저장됩니다.
1GB 텍스트는 약 1B 문자입니다. 영어 단어는 평균 4.5 자, 또는 5.5 문자를 포함하여 공백을 포함합니다. 따라서 1GB의 텍스트는 약 181m 단어입니다.
30 개의 스크립트를 병렬로 운영하면 1GB의 순수한 텍스트를 다운로드하고 청소하는 데 3 시간이 걸렸습니다. 따라서 50GB의 순수한 텍스트를 얻는 데 5 일이 걸렸습니다.
OpenAI 데이터 세트에는 40GB가 있으며 약 7-8 억 단어가 포함 된 것으로 추정됩니다. Good Reddit URL 및 Gutenberg 책에서 모든 웹 페이지를 다운로드하면 OpenAi의 웹 텍스트보다 더 큰 데이터 세트가 있어야합니다.
Openai는 GPT-2에 대한 논문에 겹치는 것에 대한 두려움에 대한 Wikipedia 기사를 포함하지 않았습니다. lazynlp.estimate_overlap_bf(bf, target_file, gran='word', n=8 사용하여 기존 데이터 세트와 일정량의 중첩이있는 Wikipedia 기사를 포함하도록 선택할 수 있습니다.