{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "9b7d6163-bb7b-44f9-8ca2-fb20e588efac", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting gensim\n", " Using cached gensim-4.3.3-cp312-cp312-win_amd64.whl.metadata (8.2 kB)\n", "Requirement already satisfied: numpy in c:\\programdata\\anaconda3\\lib\\site-packages (2.1.3)\n", "Collecting numpy\n", " Using cached numpy-1.26.4-cp312-cp312-win_amd64.whl.metadata (61 kB)\n", "Collecting scipy<1.14.0,>=1.7.0 (from gensim)\n", " Using cached scipy-1.13.1-cp312-cp312-win_amd64.whl.metadata (60 kB)\n", "Collecting smart-open>=1.8.1 (from gensim)\n", " Using cached smart_open-7.1.0-py3-none-any.whl.metadata (24 kB)\n", "Requirement already satisfied: wrapt in c:\\programdata\\anaconda3\\lib\\site-packages (from smart-open>=1.8.1->gensim) (1.17.0)\n", "Using cached gensim-4.3.3-cp312-cp312-win_amd64.whl (24.0 MB)\n", "Using cached numpy-1.26.4-cp312-cp312-win_amd64.whl (15.5 MB)\n", "Downloading scipy-1.13.1-cp312-cp312-win_amd64.whl (45.9 MB)\n", " ---------------------------------------- 0.0/45.9 MB ? eta -:--:--\n", " ---------------------------------------- 0.0/45.9 MB ? eta -:--:--\n", " ---------------------------------------- 0.5/45.9 MB 3.4 MB/s eta 0:00:14\n", " --------------------------------------- 0.8/45.9 MB 2.0 MB/s eta 0:00:23\n", " - -------------------------------------- 1.3/45.9 MB 2.3 MB/s eta 0:00:20\n", " - -------------------------------------- 1.8/45.9 MB 2.3 MB/s eta 0:00:20\n", " -- ------------------------------------- 2.4/45.9 MB 2.2 MB/s eta 0:00:20\n", " -- ------------------------------------- 2.6/45.9 MB 2.3 MB/s eta 0:00:20\n", " -- ------------------------------------- 3.1/45.9 MB 2.2 MB/s eta 0:00:20\n", " --- ------------------------------------ 3.7/45.9 MB 2.2 MB/s eta 0:00:19\n", " --- ------------------------------------ 4.2/45.9 MB 2.2 MB/s eta 0:00:19\n", " --- ------------------------------------ 4.5/45.9 MB 2.2 MB/s eta 0:00:19\n", " ---- ----------------------------------- 5.0/45.9 MB 2.2 MB/s eta 0:00:19\n", " ---- ----------------------------------- 5.5/45.9 MB 2.2 MB/s eta 0:00:19\n", " ----- ---------------------------------- 5.8/45.9 MB 2.2 MB/s eta 0:00:19\n", " ----- ---------------------------------- 6.3/45.9 MB 2.2 MB/s eta 0:00:18\n", " ----- ---------------------------------- 6.8/45.9 MB 2.2 MB/s eta 0:00:18\n", " ------ --------------------------------- 7.3/45.9 MB 2.2 MB/s eta 0:00:18\n", " ------ --------------------------------- 7.6/45.9 MB 2.2 MB/s eta 0:00:18\n", " ------- -------------------------------- 8.1/45.9 MB 2.2 MB/s eta 0:00:18\n", " ------- -------------------------------- 8.7/45.9 MB 2.2 MB/s eta 0:00:17\n", " ------- -------------------------------- 9.2/45.9 MB 2.2 MB/s eta 0:00:17\n", " -------- ------------------------------- 9.4/45.9 MB 2.2 MB/s eta 0:00:17\n", " -------- ------------------------------- 10.0/45.9 MB 2.2 MB/s eta 0:00:17\n", " --------- ------------------------------ 10.5/45.9 MB 2.2 MB/s eta 0:00:17\n", " --------- ------------------------------ 10.7/45.9 MB 2.2 MB/s eta 0:00:16\n", " --------- ------------------------------ 11.3/45.9 MB 2.2 MB/s eta 0:00:16\n", " ---------- ----------------------------- 11.8/45.9 MB 2.2 MB/s eta 0:00:16\n", " ---------- ----------------------------- 12.3/45.9 MB 2.2 MB/s eta 0:00:16\n", " ---------- ----------------------------- 12.6/45.9 MB 2.2 MB/s eta 0:00:16\n", " ----------- ---------------------------- 13.1/45.9 MB 2.1 MB/s eta 0:00:16\n", " ----------- ---------------------------- 13.4/45.9 MB 2.2 MB/s eta 0:00:16\n", " ------------ --------------------------- 13.9/45.9 MB 2.1 MB/s eta 0:00:15\n", " ------------ --------------------------- 14.4/45.9 MB 2.2 MB/s eta 0:00:15\n", " ------------ --------------------------- 14.7/45.9 MB 2.2 MB/s eta 0:00:15\n", " ------------- -------------------------- 15.2/45.9 MB 2.2 MB/s eta 0:00:15\n", " ------------- -------------------------- 15.7/45.9 MB 2.2 MB/s eta 0:00:14\n", " ------------- -------------------------- 16.0/45.9 MB 2.2 MB/s eta 0:00:14\n", " -------------- ------------------------- 16.5/45.9 MB 2.2 MB/s eta 0:00:14\n", " -------------- ------------------------- 17.0/45.9 MB 2.2 MB/s eta 0:00:14\n", " --------------- ------------------------ 17.3/45.9 MB 2.2 MB/s eta 0:00:14\n", " --------------- ------------------------ 17.8/45.9 MB 2.2 MB/s eta 0:00:14\n", " --------------- ------------------------ 18.4/45.9 MB 2.2 MB/s eta 0:00:13\n", " ---------------- ----------------------- 18.9/45.9 MB 2.1 MB/s eta 0:00:13\n", " ---------------- ----------------------- 19.1/45.9 MB 2.2 MB/s eta 0:00:13\n", " ----------------- ---------------------- 19.7/45.9 MB 2.2 MB/s eta 0:00:13\n", " ----------------- ---------------------- 20.2/45.9 MB 2.2 MB/s eta 0:00:12\n", " ----------------- ---------------------- 20.4/45.9 MB 2.2 MB/s eta 0:00:12\n", " ------------------ --------------------- 21.0/45.9 MB 2.2 MB/s eta 0:00:12\n", " ------------------ --------------------- 21.5/45.9 MB 2.2 MB/s eta 0:00:12\n", " ------------------ --------------------- 21.8/45.9 MB 2.2 MB/s eta 0:00:12\n", " ------------------- -------------------- 22.3/45.9 MB 2.2 MB/s eta 0:00:11\n", " ------------------- -------------------- 22.8/45.9 MB 2.2 MB/s eta 0:00:11\n", " -------------------- ------------------- 23.3/45.9 MB 2.2 MB/s eta 0:00:11\n", " -------------------- ------------------- 23.6/45.9 MB 2.2 MB/s eta 0:00:11\n", " --------------------- ------------------ 24.1/45.9 MB 2.2 MB/s eta 0:00:11\n", " --------------------- ------------------ 24.6/45.9 MB 2.2 MB/s eta 0:00:10\n", " --------------------- ------------------ 24.9/45.9 MB 2.2 MB/s eta 0:00:10\n", " ---------------------- ----------------- 25.4/45.9 MB 2.2 MB/s eta 0:00:10\n", " ---------------------- ----------------- 26.0/45.9 MB 2.2 MB/s eta 0:00:10\n", " ---------------------- ----------------- 26.2/45.9 MB 2.2 MB/s eta 0:00:10\n", " ----------------------- ---------------- 26.7/45.9 MB 2.2 MB/s eta 0:00:09\n", " ----------------------- ---------------- 27.3/45.9 MB 2.2 MB/s eta 0:00:09\n", " ----------------------- ---------------- 27.5/45.9 MB 2.2 MB/s eta 0:00:09\n", " ------------------------ --------------- 27.8/45.9 MB 2.2 MB/s eta 0:00:09\n", " ------------------------ --------------- 28.3/45.9 MB 2.1 MB/s eta 0:00:09\n", " ------------------------- -------------- 28.8/45.9 MB 2.1 MB/s eta 0:00:08\n", " ------------------------- -------------- 29.1/45.9 MB 2.1 MB/s eta 0:00:08\n", " ------------------------- -------------- 29.6/45.9 MB 2.1 MB/s eta 0:00:08\n", " -------------------------- ------------- 29.9/45.9 MB 2.1 MB/s eta 0:00:08\n", " -------------------------- ------------- 30.4/45.9 MB 2.1 MB/s eta 0:00:08\n", " -------------------------- ------------- 30.7/45.9 MB 2.1 MB/s eta 0:00:08\n", " --------------------------- ------------ 31.2/45.9 MB 2.1 MB/s eta 0:00:07\n", " --------------------------- ------------ 31.7/45.9 MB 2.1 MB/s eta 0:00:07\n", " --------------------------- ------------ 32.0/45.9 MB 2.1 MB/s eta 0:00:07\n", " ---------------------------- ----------- 32.2/45.9 MB 2.1 MB/s eta 0:00:07\n", " ---------------------------- ----------- 32.8/45.9 MB 2.1 MB/s eta 0:00:07\n", " ----------------------------- ---------- 33.3/45.9 MB 2.1 MB/s eta 0:00:06\n", " ----------------------------- ---------- 33.6/45.9 MB 2.1 MB/s eta 0:00:06\n", " ----------------------------- ---------- 34.1/45.9 MB 2.1 MB/s eta 0:00:06\n", " ----------------------------- ---------- 34.3/45.9 MB 2.1 MB/s eta 0:00:06\n", " ------------------------------ --------- 34.6/45.9 MB 2.1 MB/s eta 0:00:06\n", " ------------------------------ --------- 35.1/45.9 MB 2.1 MB/s eta 0:00:06\n", " ------------------------------- -------- 35.7/45.9 MB 2.1 MB/s eta 0:00:05\n", " ------------------------------- -------- 35.9/45.9 MB 2.1 MB/s eta 0:00:05\n", " ------------------------------- -------- 36.2/45.9 MB 2.1 MB/s eta 0:00:05\n", " ------------------------------- -------- 36.7/45.9 MB 2.1 MB/s eta 0:00:05\n", " -------------------------------- ------- 37.0/45.9 MB 2.1 MB/s eta 0:00:05\n", " -------------------------------- ------- 37.5/45.9 MB 2.1 MB/s eta 0:00:05\n", " --------------------------------- ------ 38.0/45.9 MB 2.1 MB/s eta 0:00:04\n", " --------------------------------- ------ 38.3/45.9 MB 2.1 MB/s eta 0:00:04\n", " --------------------------------- ------ 38.8/45.9 MB 2.1 MB/s eta 0:00:04\n", " ---------------------------------- ----- 39.1/45.9 MB 2.1 MB/s eta 0:00:04\n", " ---------------------------------- ----- 39.6/45.9 MB 2.1 MB/s eta 0:00:04\n", " ---------------------------------- ----- 39.8/45.9 MB 2.1 MB/s eta 0:00:03\n", " ----------------------------------- ---- 40.4/45.9 MB 2.1 MB/s eta 0:00:03\n", " ----------------------------------- ---- 40.6/45.9 MB 2.1 MB/s eta 0:00:03\n", " ----------------------------------- ---- 41.2/45.9 MB 2.1 MB/s eta 0:00:03\n", " ------------------------------------ --- 41.4/45.9 MB 2.1 MB/s eta 0:00:03\n", " ------------------------------------ --- 41.9/45.9 MB 2.1 MB/s eta 0:00:02\n", " ------------------------------------ --- 42.2/45.9 MB 2.1 MB/s eta 0:00:02\n", " ------------------------------------- -- 42.7/45.9 MB 2.1 MB/s eta 0:00:02\n", " ------------------------------------- -- 43.0/45.9 MB 2.1 MB/s eta 0:00:02\n", " ------------------------------------- -- 43.3/45.9 MB 2.1 MB/s eta 0:00:02\n", " -------------------------------------- - 43.8/45.9 MB 2.1 MB/s eta 0:00:02\n", " -------------------------------------- - 44.3/45.9 MB 2.1 MB/s eta 0:00:01\n", " -------------------------------------- - 44.6/45.9 MB 2.1 MB/s eta 0:00:01\n", " --------------------------------------- 45.1/45.9 MB 2.1 MB/s eta 0:00:01\n", " --------------------------------------- 45.4/45.9 MB 2.1 MB/s eta 0:00:01\n", " --------------------------------------- 45.9/45.9 MB 2.1 MB/s eta 0:00:01\n", " ---------------------------------------- 45.9/45.9 MB 2.0 MB/s eta 0:00:00\n", "Downloading smart_open-7.1.0-py3-none-any.whl (61 kB)\n", "Installing collected packages: smart-open, numpy, scipy, gensim\n", " Attempting uninstall: numpy\n", " Found existing installation: numpy 2.1.3\n", " Uninstalling numpy-2.1.3:\n", " Successfully uninstalled numpy-2.1.3\n", " Attempting uninstall: scipy\n", " Found existing installation: scipy 1.15.1\n", " Uninstalling scipy-1.15.1:\n", " Successfully uninstalled scipy-1.15.1\n", "Successfully installed gensim-4.3.3 numpy-1.26.4 scipy-1.13.1 smart-open-7.1.0\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ " WARNING: Failed to remove contents in a temporary directory 'C:\\Users\\LGR\\AppData\\Local\\Temp\\pip-uninstall-bzrgm1pe'.\n", " You can safely remove it manually.\n", " WARNING: Failed to remove contents in a temporary directory 'C:\\ProgramData\\anaconda3\\Lib\\site-packages\\~~mpy.libs'.\n", " You can safely remove it manually.\n", "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", "tensorflow-intel 2.18.0 requires ml-dtypes<0.5.0,>=0.4.0, but you have ml-dtypes 0.5.1 which is incompatible.\n", "tensorflow-intel 2.18.0 requires tensorboard<2.19,>=2.18, but you have tensorboard 2.19.0 which is incompatible.\n", "bokeh 3.6.2 requires tornado>=6.2, but you have tornado 6.1 which is incompatible.\n", "scikit-image 0.25.0 requires pillow>=10.1, but you have pillow 9.5.0 which is incompatible.\n" ] } ], "source": [ "!pip install gensim numpy" ] }, { "cell_type": "code", "execution_count": 2, "id": "a6600c17-fb8e-4e8c-a6a1-d25084447144", "metadata": {}, "outputs": [], "source": [ "import gensim.downloader as api\n", "\n", "# Bu satır modeli ilk kez indirir ve önbelleğe alır\n", "model = api.load(\"word2vec-google-news-300\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "6d55403c-62fc-4d07-9306-ca11593bcaa2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.05226295" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# En benzer kelimeleri getir\n", "model.most_similar(\"spy\")\n", "\n", "# İki kelime arasındaki benzerlik\n", "model.similarity(\"dog\", \"cat\")\n", "model.similarity(\"dog\", \"explosion\")" ] }, { "cell_type": "markdown", "id": "e56a26c9-a705-4e54-83e2-331e03586f36", "metadata": {}, "source": [ "AI Strateji Fonksiyonu: oner_ipucu()\n", "Bu fonksiyon:\n", "\n", "Hedef kelimelere yakın\n", "\n", "Yasaklı kelimelere uzak\n", "olan en iyi ipucunu seçecek." ] }, { "cell_type": "code", "execution_count": 4, "id": "8d01664b-2ca0-407c-a51c-55f19ec5615f", "metadata": {}, "outputs": [], "source": [ "def oner_ipucu(hedefler, yasaklar, model, aday_kelimeler=None, top_n=1):\n", " from numpy import mean\n", "\n", " # Hedef ve yasaklı kelimeleri dışlayacağımız bir set\n", " filtre = set(hedefler + yasaklar)\n", "\n", " if aday_kelimeler is None:\n", " aday_kelimeler = list(model.key_to_index.keys())\n", "\n", " en_iyi_ipucu = None\n", " en_iyi_skor = -float(\"inf\")\n", "\n", " for kelime in aday_kelimeler:\n", " if kelime in filtre:\n", " continue # hedef ya da yasaklılardan biri zaten, geç\n", "\n", " try:\n", " hedef_skor = mean([model.similarity(kelime, h) for h in hedefler if h in model])\n", " yasak_skor = mean([model.similarity(kelime, y) for y in yasaklar if y in model])\n", " toplam_skor = hedef_skor - yasak_skor\n", "\n", " if toplam_skor > en_iyi_skor:\n", " en_iyi_skor = toplam_skor\n", " en_iyi_ipucu = kelime\n", "\n", " except KeyError:\n", " continue\n", "\n", " return en_iyi_ipucu\n", "\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "a24840d8-ecfe-4119-a25a-514e9ec42a55", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "🔍 Geliştirilmiş Önerilen ipucu: cats\n" ] } ], "source": [ "hedefler = [\"dog\", \"cat\", \"fish\"]\n", "yasaklar = [\"bomb\", \"knife\", \"gun\"]\n", "\n", "ipucu = oner_ipucu(hedefler, yasaklar, model)\n", "print(\"🔍 Geliştirilmiş Önerilen ipucu:\", ipucu)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "b56df5e1-eb56-4a4b-83a4-172476551353", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.9" } }, "nbformat": 4, "nbformat_minor": 5 }