Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,19 +22,18 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
| 22 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 23 |
from sentence_transformers import SentenceTransformer
|
| 24 |
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# モデルをロード
|
| 27 |
model = SentenceTransformer("all-MiniLM-L6-v2") # 768次元の埋め込みを生成
|
| 28 |
-
|
| 29 |
-
# FAISSインデックスを作り直す
|
| 30 |
-
embedding_dim = 768 # ここをモデルに合わせる
|
| 31 |
-
index = faiss.IndexFlatL2(embedding_dim) # L2距離で検索
|
| 32 |
-
|
| 33 |
# 既存のインデックスファイルを削除する(手動で削除するか、スクリプトで削除する)
|
| 34 |
-
import os
|
| 35 |
if os.path.exists("faiss_index"):
|
| 36 |
os.remove("faiss_index")
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
# 新しいインデックスを保存
|
| 39 |
faiss.write_index(index, "faiss_index")
|
| 40 |
|
|
|
|
| 22 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 23 |
from sentence_transformers import SentenceTransformer
|
| 24 |
|
| 25 |
+
model = SentenceTransformer("all-MiniLM-L6-v2") # 例
|
| 26 |
+
print(model.get_sentence_embedding_dimension()) # 768 のはず
|
| 27 |
|
| 28 |
# モデルをロード
|
| 29 |
model = SentenceTransformer("all-MiniLM-L6-v2") # 768次元の埋め込みを生成
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# 既存のインデックスファイルを削除する(手動で削除するか、スクリプトで削除する)
|
|
|
|
| 31 |
if os.path.exists("faiss_index"):
|
| 32 |
os.remove("faiss_index")
|
| 33 |
|
| 34 |
+
# FAISSインデックスを作り直す
|
| 35 |
+
embedding_dim = 768 # ここをモデルに合わせる
|
| 36 |
+
index = faiss.IndexFlatL2(embedding_dim) # L2距離で検索
|
| 37 |
# 新しいインデックスを保存
|
| 38 |
faiss.write_index(index, "faiss_index")
|
| 39 |
|