Upload 4 files
Browse files- .gitattributes +35 -0
- README.md +13 -0
- app.py +55 -0
- requirements.txt +5 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: YouNameIt
|
3 |
+
emoji: 📉
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: blue
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.26.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: cc
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from tqdm import tqdm
|
4 |
+
from peft import PeftModel, PeftConfig
|
5 |
+
from transformers import AutoModelForSeq2SeqLM
|
6 |
+
from transformers import AutoTokenizer
|
7 |
+
|
8 |
+
config = PeftConfig.from_pretrained("NursNurs/T5ForReverseDictionary")
|
9 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
|
10 |
+
model = PeftModel.from_pretrained(model, "NursNurs/T5ForReverseDictionary")
|
11 |
+
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
|
13 |
+
|
14 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
+
|
16 |
+
def return_top_k(sentence, k=10):
|
17 |
+
|
18 |
+
inputs = [f"Descripton : {sentence}. Word : "]
|
19 |
+
|
20 |
+
inputs = tokenizer(
|
21 |
+
inputs,
|
22 |
+
padding=True, truncation=True,
|
23 |
+
return_tensors="pt",
|
24 |
+
)
|
25 |
+
|
26 |
+
|
27 |
+
model.to(device)
|
28 |
+
|
29 |
+
with torch.no_grad():
|
30 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
31 |
+
output_sequences = model.generate(input_ids=inputs["input_ids"], max_new_tokens=10, num_beams=k, num_return_sequences=k, #max_length=3,
|
32 |
+
top_p = 50, output_scores=True, return_dict_in_generate=True) #repetition_penalty=10000.0
|
33 |
+
#print("output_sequences", output_sequences)
|
34 |
+
logits = output_sequences['sequences_scores'].clone().detach()
|
35 |
+
decoded_probabilities = torch.softmax(logits, dim=0)
|
36 |
+
|
37 |
+
|
38 |
+
#all word predictions
|
39 |
+
predictions = [tokenizer.decode(tokens, skip_special_tokens=True) for tokens in output_sequences['sequences']]
|
40 |
+
probabilities = [round(float(prob), 2) for prob in decoded_probabilities]
|
41 |
+
|
42 |
+
return predictions
|
43 |
+
|
44 |
+
|
45 |
+
st.title("You name it!")
|
46 |
+
|
47 |
+
# adding the text that will show in the text box as default
|
48 |
+
default_value = "Type the description of the word you have in mind!"
|
49 |
+
|
50 |
+
sent = st.text_area("Text", default_value, height = 275)
|
51 |
+
|
52 |
+
result = return_top_k(sent)
|
53 |
+
st.write("Here are my guesses about your word:")
|
54 |
+
st.write(result)
|
55 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
peft==0.5.0
|
2 |
+
streamlit==1.26.0
|
3 |
+
torch==1.13.1
|
4 |
+
tqdm==4.64.1
|
5 |
+
transformers==4.33.2
|