クロール、クリーンアップ、および重複するウェブページを容易にするために、大規模な単一言語データセットを作成できる簡単なライブラリ。このライブラリを使用して、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つのKarmaと重複したリンクのリストを提供するのに十分親切です。
2015 - 06年から2018-10の間に約23mのURLがあり、そのうち約40〜60%が悪いURLです(URLは存在しなくなったか、スクレーパーフレンドリーではありません)。これは、これからすべての良いURLをダウンロードしてクリーニングした後、約10mのWebページまたは50GBの純粋なテキストが必要であることを意味します。
すべてのURLのリストを、Gutenbergの本からダウンロードできます。 5万冊の本があり、約14GBの純粋なテキストに変換されます。
lazynlp.get_us_gutenberg_links()を実行して同じリストを取得することもできます。たとえば、すべてのGutenberg URLを取得してファイルus_gutenberg.urlsに保存する場合は、次のコマンドを実行します。これには半日かかるかもしれません。
lazynlp.get_us_gutenberg_links('us_gutenberg.urls')
すべてのURLのリストをオーストラリアのグーテンバーグブックにダウンロードすることができます。約1GBの純粋なテキストに変換される4Kの本があります。
lazynlp.get_aus_gutenberg_links()を実行して同じリストを取得することもできます。たとえば、すべてのGutenberg URLを取得してファイルに保存したい場合は、 aus_gutenberg.urls :
lazynlp.get_aus_gutenberg_links('aus_gutenberg.urls')
Wikipedia Dumpsはこちらからダウンロードできます。
同じURLを複数回ダウンロードしたくありません。すべてのURLを推定するのに役立つ2つの機能があります。
lazynlp.dedup_lines(files, outfold)
この関数は、ファイルのリスト(各ファイル、各行、各行はURLS)を取り、各ファイルを以前のすべてのファイルに対して布priseします。重複排除されたすべてのファイルをOutfoldに保存します。
lazynlp.dedup_lines_from_new_file(original_files, new_file, outfile)
この関数を使用すると、以前に重複排除されたすべてのファイル(Original_files)に対して新しいファイルを容易にすることができます
各Webページを個別にダウンロードする場合は、次のことを呼び出します。
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を文字列にデコードし、外国人文字を崩壊させ、白スペースを崩壊させ、印刷できないキャラクターを交換し、UNESCAPE 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 、「チャー」または「単語」レベルのトークンの穀物です。
nはn-gramです。
capacityとerror_rateは、使用されるBloomFilter用です。
header :スキップする各ファイルの行数。私たちの形式では、最初の行がURLだからです
既存のBloomFilterとターゲットファイルの重複量を推定するには、この関数を使用します。
lazynlp.estimate_overlap_bf(bf, target_file, gran='word', n=8, header=0)
ファイルのリストが与えられた場合、例えばクリーンされたWebページで、他のファイルと重複する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文字を含む5.5文字があります。したがって、1GBのテキストは約1,81mの単語です。
並行して30のスクリプトを実行したとき、1GBの純粋なテキストをダウンロードしてクリーニングするのに3時間かかりました。したがって、50GBの純粋なテキストを取得するには5日かかります。
OpenAIデータセットには40GBがあり、これには約700万億から80億語が含まれていると推定されています。 Good Reddit URLとGutenbergの本からすべてのWebページをダウンロードすると、OpenaiのWebtextよりも大きなデータセットが必要です。
Openaiは、GPT-2の論文には、重複することを恐れてウィキペディアの記事を含めていませんでした。 lazynlp.estimate_overlap_bf(bf, target_file, gran='word', n=8使用して、既存のデータセットとの一定量未満の重複があるウィキペディア記事を含めることを選択できます。