ห้องสมุดที่ตรงไปตรงมาที่ช่วยให้คุณคลานทำความสะอาดและหักล้างหน้าเว็บเพื่อสร้างชุดข้อมูล monolingual ขนาดใหญ่ การใช้ไลบรารีนี้คุณควรจะสามารถสร้างชุดข้อมูลที่ใหญ่กว่าที่ใช้โดย OpenAI สำหรับ GPT-2
ไลบรารีนี้ใช้ 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 ใจดีพอที่จะให้รายการลิงก์ที่หักสำรองด้วย Karma อย่างน้อย 3 Karma ที่คุณสามารถดาวน์โหลดได้ที่นี่
มี URL ประมาณ 23 เมตรระหว่างปี 2558-2559 ถึง 2561-10 ซึ่งประมาณ 40-60 % เป็น URL ที่ไม่ดี (URL ไม่มีอยู่อีกต่อไปหรือไม่เป็นมิตรกับมีดโกน) หมายความว่าหลังจากที่คุณดาวน์โหลดและทำความสะอาด URL ที่ดีทั้งหมดจากนี้คุณควรมีหน้าเว็บประมาณ 10 เมตรหรือข้อความบริสุทธิ์ 50GB
คุณสามารถดาวน์โหลดรายการ URL ทั้งหมดไปยังเราหนังสือ Gutenberg ได้ที่นี่ มีหนังสือ 50k ซึ่งแปลงเป็นข้อความบริสุทธิ์ประมาณ 14GB
คุณยังสามารถเรียกใช้ lazynlp.get_us_gutenberg_links() เพื่อรับรายการเดียวกัน ตัวอย่างเช่นหากคุณต้องการรับ URL ของ Gutenberg ทั้งหมดและเก็บไว้ในไฟล์ us_gutenberg.urls ให้เรียกใช้คำสั่งต่อไปนี้ อาจใช้เวลาครึ่งวัน
lazynlp.get_us_gutenberg_links('us_gutenberg.urls')
คุณสามารถดาวน์โหลดรายการ URL ทั้งหมดไปยังหนังสือ Australian Gutenberg ได้ที่นี่ มีหนังสือ 4K ซึ่งแปลงเป็นข้อความบริสุทธิ์ประมาณ 1GB
นอกจากนี้คุณยังสามารถเรียกใช้ lazynlp.get_aus_gutenberg_links() เพื่อรับรายการเดียวกัน ตัวอย่างเช่นหากคุณต้องการรับ URL ของ Gutenberg ทั้งหมดและเก็บไว้ในไฟล์ aus_gutenberg.urls :
lazynlp.get_aus_gutenberg_links('aus_gutenberg.urls')
คุณสามารถดาวน์โหลด Wikipedia Dumps ได้ที่นี่
คุณไม่ต้องการดาวน์โหลด URL เดียวกันหลายครั้ง มีสองฟังก์ชั่นที่ช่วยให้คุณลด URL ทั้งหมด:
lazynlp.dedup_lines(files, outfold)
ฟังก์ชั่นนี้ใช้ในรายการไฟล์ (ในแต่ละไฟล์แต่ละบรรทัดเป็น URL) และ deduplication แต่ละไฟล์กับไฟล์ก่อนหน้าทั้งหมด บันทึกไฟล์ที่หักสำรองทั้งหมดใน 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 ลงในสตริงอักขระต่างประเทศที่มีการแปล, การยุบพื้นที่สีขาว, แทนที่อักขระที่ไม่สามารถพิมพ์ได้, Unsescape HTML ฯลฯ โดยใช้วิธีการที่มีอยู่ใน lazynlp/cleaner.py
นอกจากนี้คุณยังสามารถเรียกใช้ฟังก์ชั่นต่อไปนี้เพื่อทำการประมวลผลส่วนใหญ่
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 เป็น Granulary of Tokens: 'char' หรือ 'word' ระดับ
n คือ N-Gram
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 สคริปต์แบบขนานมันใช้เวลา 3 ชั่วโมงในการดาวน์โหลดและทำความสะอาดข้อความบริสุทธิ์ 1GB ดังนั้นต้องใช้เวลา 5 วันในการรับข้อความบริสุทธิ์ 50GB
ชุดข้อมูล OpenAI มี 40GB ซึ่งฉันประเมินว่ามีประมาณ 7-8 พันล้านคำ หากคุณดาวน์โหลดเว็บเพจทั้งหมดจากหนังสือ URL Reddit และ Gutenberg ที่ดีคุณควรมีชุดข้อมูลที่ใหญ่กว่า WebText ของ OpenAI
Openai ในกระดาษของพวกเขาสำหรับ GPT-2 ไม่ได้รวมบทความ Wikipedia เพราะกลัวการทับซ้อนกัน คุณสามารถเลือกที่จะรวมบทความ Wikipedia ที่มีจำนวนน้อยกว่าการซ้อนทับกับชุดข้อมูลที่มีอยู่โดยใช้ lazynlp.estimate_overlap_bf(bf, target_file, gran='word', n=8