Skip to Content
PyTorch によるコーダーのための AI および ML
book

PyTorch によるコーダーのための AI および ML

by Laurence Moroney
July 2025
Intermediate to advanced
444 pages
7h 8m
Japanese
O'Reilly Media, Inc.
Content preview from PyTorch によるコーダーのための AI および ML

第6章 エンベッディングを使ってセンチメントをプログラマブルにする

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

第5章では、単語を 、トークンにエンコーディングする方法を見た。そして、単語でいっぱいの文章をトークンでいっぱいのシーケンスにエンコーディングし、適宜パディングしたり切り詰めたりして、最終的にニューラルネットワークの訓練に使える形の良いデータセットにする方法を見た。しかし、その中に単語の意味をモデル化したものはない。意味をカプセル化できる絶対的な数値エンコーディングがないのは事実だが、相対的なものはある。

この章では、意味をカプセル化するテクニック、特に高次元空間のベクトルを作成して単語を表現するエンベッディングの概念について学ぶ。これらのベクトルの方向は、コーパス中の単語の使用に基づいて、時間をかけて学習することができる。そして、ある文章が与えられたときに、単語のベクトルの方向を調べ、それらを合計し、その合計の全体的な方向から、その文章のセンチメントを単語の積として確定することができる。また、これに関連して、モデルが文章をスキャンする際、文中の単語の位置関係も適切な埋め込みを学習するのに役立つ。

この章では、その仕組みも探る。第5章の皮肉検出のためのニュースヘッドラインデータセットを使って、文中の皮肉を検出するモデルを助ける埋め込みを構築する。また、コーパスの単語がどのようにベクトルにマッピングされるかを理解するのに役立つクールな可視化ツールを使って、どの単語が全体の分類を決定するかを確認する。

単語から意味を確立する

埋め込み用の高次元ベクトル()に入る前に、いくつかの簡単な例を使って、数値からどのように意味を導き出せるかを視覚化してみよう。第5章の皮肉データセットを使って、皮肉な見出しを構成する単語を正の数で、現実的な見出しを構成する単語を負の数でエンコーディングしたらどうなるだろうか

簡単な例肯定と否定

例えば、データセットからこの皮肉な見出しを見てみよう:

christian bale given neutered male statuette named oscar

語彙のすべての単語が0から始まると仮定すると、この文の各単語の値に1を足すと、このようになる:

{ "christian" : 1, "bale" : 1, "given" : 1, "neutered": 1, "male" : 1, 
  "statuette": 1, "named" : 1, "oscar": 1}

これは前章で行った単語のトークン化とは違う。各単語(例えばchristian)をコーパスからエンコーディングされたそれを表すトークンに置き換えることも考えられるが、コードを読みやすくするため、とりあえず単語はそのままにしておく。

次のステップでは、(皮肉ではない)普通の見出しを考えてみよう:

gareth bale scores wonder goal against germany

これは異なる感情なので、代わりに各単語の現在の値から1を減算することができ、差集合は次のようになる:

{ "christian" : 1, "bale" : 0, "given" : 1, "neutered": 1, "male" : 1,
  "statuette": 1, "named" : 1, "oscar": 1, "gareth" : 1, "scores" ...
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 ―絵を描き、物語や音楽を作り、ゲームをプレイする

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

David Foster, 松田 晃一, 小沼 千絵
ダイナミックリチーミング 第2版 ―5つのパターンによる効果的なチーム編成

ダイナミックリチーミング 第2版 ―5つのパターンによる効果的なチーム編成

Heidi Helfand, 永瀬 美穂, 吉羽 龍太郎, 原田 騎郎, 細澤 あゆみ

Publisher Resources

ISBN: 9798341662636