Update README.md
Browse files
README.md
CHANGED
@@ -34,11 +34,36 @@ This model is an attempt to simplify code understanding by generating line by li
|
|
34 |
# Model Usage
|
35 |
|
36 |
```py
|
37 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
```
|
44 |
|
|
|
34 |
# Model Usage
|
35 |
|
36 |
```py
|
37 |
+
from transformers import (
|
38 |
+
AutoModelForSeq2SeqLM,
|
39 |
+
AutoTokenizer,
|
40 |
+
AutoConfig,
|
41 |
+
pipeline,
|
42 |
+
)
|
43 |
|
44 |
+
model_name = "sagard21/python-code-explainer"
|
45 |
|
46 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, padding=True)
|
47 |
+
|
48 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
49 |
+
|
50 |
+
config = AutoConfig.from_pretrained(model_name)
|
51 |
+
|
52 |
+
model.eval()
|
53 |
+
|
54 |
+
pipe = pipeline("summarization", model=model_name, config=config, tokenizer=tokenizer)
|
55 |
+
|
56 |
+
raw_code = """
|
57 |
+
def preprocess(text: str) -> str:
|
58 |
+
text = str(text)
|
59 |
+
text = text.replace("\n", " ")
|
60 |
+
tokenized_text = text.split(" ")
|
61 |
+
preprocessed_text = " ".join([token for token in tokenized_text if token])
|
62 |
+
|
63 |
+
return preprocessed_text
|
64 |
+
"""
|
65 |
+
|
66 |
+
print(pipe(raw_code)[0]["summary_text"])
|
67 |
|
68 |
```
|
69 |
|