Skip to Content
Deep Learning 向けの PyTorch プログラミング
book

Deep Learning 向けの PyTorch プログラミング

by Ian Pointer
May 2025
Intermediate to advanced
220 pages
3h 27m
Japanese
O'Reilly Media, Inc.
Content preview from Deep Learning 向けの PyTorch プログラミング

第5章. テキストの分類

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

画像はひとまず置いておいて、ディープラーニングが従来のテクニックを大きく前進させることが証明されている別の分野に目を向ける。自然言語処理(NLP)である。その良い例が、Google翻訳だ。元々、翻訳を処理するコードは50万行にも及んだ。新しいTensorFlowベースのシステムは約500行で、旧来の方法よりも優れたパフォーマンスを発揮している。

また、第4章で学んだ転移学習(transfer learning)をNLPの問題に導入する際にも、最近の飛躍的な進歩があった。Transformerアーキテクチャのような新しいアーキテクチャは、OpenAIのGPT-2のようなネットワークの創造につながった。GPT-2は、より大きなバリエーションで、ほとんど人間のような品質のテキストを生成する(実際、OpenAIは悪意を持って使われることを恐れて、このモデルの重みを公開していない)。

この章では、リカレント・ニューラル・ネットワークと埋め込みについて一通り説明する。そして、torchtext ライブラリと、それを LSTM ベースのモデルでテキスト処理に使う方法を探る。

リカレント・ニューラル・ネットワーク

CNNベースのアーキテクチャをこれまでどのように使ってきたかを振り返ってみると、常に1つの完全なスナップショットで作業してきたことがわかる。しかし、この2つの文章の断片を考えてみよう:

The cat sat on the mat.

She got up and impatiently climbed on the chair, meowing for food.

この2つの文章を次々にCNNに送り込み、「猫はどこだ」と尋ねたとしよう。ネットワークには記憶の概念がないからだ。このことは、時間的領域を持つデータ(テキスト、音声、ビデオ、時系列データなど)を扱う際には非常に重要である。1リカレント・ニューラル・ネットワーク(RNN)は、隠れ状態を介してニューラルネットワークに記憶を与えることで、この問題に答えている。

RNNとはどのようなものか?私のお気に入りの説明は、"ニューラルネットワークとfor ループを掛け合わせたものを想像してほしい "というものだ。図5-1は、古典的なRNN構造の図である。

Classical RNN diagram
図5-1. RNN

tの時間ステップで入力を追加すると、htの 隠れ出力状態が得られ、その出力も次の時間ステップのRNNにフィードバックされる。図5-2に示すように、このネットワークを展開することで、何が起こっているのかを詳しく見ることができる。

Unrolled RNN diagram
図5-2. 展開されたRNN

ここにあるのは、(パラメータを共有する)完全接続レイヤーのグループ化、一連の入力、そして出力である。入力データがネットワークに入力され、シーケンス内の次の項目が出力として予測される。展開した図を見ると、RNNは完全接続レイヤーのパイプラインと考えることができ、連続する入力はシーケンスの次のレイヤーに供給される(レイヤー間には ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

生成 Deep Learning 第2版 ―絵を描き、物語や音楽を作り、ゲームをプレイする

生成 Deep Learning 第2版 ―絵を描き、物語や音楽を作り、ゲームをプレイする

David Foster, 松田 晃一, 小沼 千絵
直感 Deep Learning ―Python×Kerasでアイデアを形にするレシピ

直感 Deep Learning ―Python×Kerasでアイデアを形にするレシピ

Antonio Gulli, Sujit Pal, 大串 正矢, 久保 隆宏, 中山 光樹

Publisher Resources

ISBN: 9798341650367