1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

"うんこ味のカレー" or "カレー味のうんこ"、 意味ベクトルで哲学に決着をつける

1
Last updated at Posted at 2025-11-10

"うんこ味のカレー" or "カレー味のうんこ"、 意味ベクトルで哲学に決着をつける

「うんこ味のカレー」と「カレー味のうんこ」――
人類が直面する究極の二択に、Google Gemini の埋め込みと PCA でガチで向き合ってみました。

結果を先に言うと:

「カレー味のうんこ」を選ぶべきです。

image.png


分析の概要

  • Gemini APIで各単語・フレーズの意味ベクトルを取得
  • cosine 類似度ベースで単語間の意味的な「距離」を算出
  • PCAで2次元に圧縮し、散布図として可視化
  • 距離値も線で表示

比較対象は以下の4つの単語です:

  • カレー
  • うんこ
  • うんこ味のカレー
  • カレー味のうんこ

考察:意味的距離からの選択

距離のポイントはこうです:

比較 cos 距離(小さいほど近い)
カレー vs カレー味のうんこ 0.21
カレー vs うんこ味のカレー 0.25
うんこ vs カレー味のうんこ 0.24
うんこ vs うんこ味のカレー 0.14
  • カレー味のうんこ」は「うんこ」から遠く、「カレー」に近い。
  • うんこ味のカレー」は「カレー」からやや遠く、「うんこ」にやや近い。

→ つまり、「カレー味のうんこ」の方が、よりカレー寄りで、うんこ成分が薄いという結論になります。


コード(Gemini Embedding + PCA + 距離可視化)

実行環境はGoogle Colabです。

%pip install -q -U "google-genai>=1.0.0"

from google import genai
import matplotlib.pyplot as plt
import japanize_matplotlib
from sklearn.decomposition import PCA
from sklearn.metrics.pairwise import cosine_similarity
from itertools import combinations
import numpy as np

# ===== APIの使用 =====
GEMINI_API_KEY = "自分のキーをつかってください"
client = genai.Client(api_key=GEMINI_API_KEY)

# ===== パラメータ =====
words = ["カレー", "うんこ", "うんこ味のカレー", "カレー味のうんこ"]
show_distances = True
MODEL_ID = "models/embedding-001"

# ===== 埋め込み取得 =====
response = client.embed_content(model=MODEL_ID, contents=words)
embeddings = [e.values for e in response.embeddings]

# ===== PCAで2次元へ圧縮 =====
pca = PCA(n_components=2)
points_2d = pca.fit_transform(embeddings)

# ===== cos 類似度ベースの距離関数 =====
def cosine_distance(v1, v2):
    return 1 - cosine_similarity([v1], [v2])[0][0]

# ===== 図を描画 =====
plt.figure(figsize=(10, 8))

for i, label in enumerate(words):
    x, y = points_2d[i]
    plt.scatter(x, y)
    plt.text(x + 0.01, y + 0.01, label, fontsize=12)

if show_distances:
    for i, j in combinations(range(len(words)), 2):
        x1, y1 = points_2d[i]
        x2, y2 = points_2d[j]
        plt.plot([x1, x2], [y1, y2], color='gray', linewidth=0.5, alpha=0.5)
        dist = cosine_distance(embeddings[i], embeddings[j])
        xm, ym = (x1 + x2) / 2, (y1 + y2) / 2
        plt.text(xm, ym, f"{dist:.2f}", fontsize=8, color='gray', ha='center', va='center')

plt.title("うんこ味のカレー vs カレー味のうんこ:意味ベクトルの2次元可視化", fontsize=14)
plt.xlabel("PCA 1")
plt.ylabel("PCA 2")
plt.grid(True)
plt.tight_layout()
plt.show()

まとめ

意味的には「カレー味のうんこ」は「うんこ味のカレー」より“うんこ成分が薄い”

Gemini Embedding はこういう哲学的ネタにも応用できる

おまけ: 英語だと?

同じ実験を英語でもやってみました

image.png

なんとも互角。国民性が反映されている?

備考

Google Gemini APIの使用にはAPIキーと課金設定が必要です。
Gemini APIキーの発行はこちらの右上APIキーの作成ボタンから

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?