update examples
Browse files
README.md
CHANGED
@@ -13,72 +13,6 @@ metrics:
|
|
13 |
language:
|
14 |
- en
|
15 |
widget:
|
16 |
-
- text: >
|
17 |
-
import torch
|
18 |
-
|
19 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
20 |
-
|
21 |
-
|
22 |
-
checkpoint = "distilbert-base-uncased-finetuned-sst-2-english"
|
23 |
-
|
24 |
-
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
25 |
-
|
26 |
-
model = AutoModelForSequenceClassification.from_pretrained(checkpoint)
|
27 |
-
|
28 |
-
sequences = ["I've been waiting for a HuggingFace course my whole life.",
|
29 |
-
"So have I!"]
|
30 |
-
|
31 |
-
|
32 |
-
tokens = tokenizer(sequences, padding=True, truncation=True,
|
33 |
-
return_tensors="pt")
|
34 |
-
|
35 |
-
output = model(**tokens)
|
36 |
-
example_title: Example One
|
37 |
-
- text: >
|
38 |
-
import torch
|
39 |
-
|
40 |
-
from tqdm.auto import tqdm
|
41 |
-
|
42 |
-
|
43 |
-
device = torch.device("cuda") if torch.cuda.is_available() else
|
44 |
-
torch.device("cpu")
|
45 |
-
|
46 |
-
model.to(device)
|
47 |
-
|
48 |
-
|
49 |
-
progress_bar = tqdm(range(num_training_steps))
|
50 |
-
|
51 |
-
|
52 |
-
model.train()
|
53 |
-
|
54 |
-
for epoch in range(num_epochs):
|
55 |
-
for batch in train_dataloader:
|
56 |
-
batch = {k: v.to(device) for k, v in batch.items()}
|
57 |
-
outputs = model(**batch)
|
58 |
-
loss = outputs.loss
|
59 |
-
loss.backward()
|
60 |
-
|
61 |
-
optimizer.step()
|
62 |
-
lr_scheduler.step()
|
63 |
-
optimizer.zero_grad()
|
64 |
-
progress_bar.update(1)
|
65 |
-
example_title: Example Two
|
66 |
-
- text: |
|
67 |
-
import evaluate
|
68 |
-
|
69 |
-
metric = evaluate.load("glue", "mrpc")
|
70 |
-
model.eval()
|
71 |
-
for batch in eval_dataloader:
|
72 |
-
batch = {k: v.to(device) for k, v in batch.items()}
|
73 |
-
with torch.no_grad():
|
74 |
-
outputs = model(**batch)
|
75 |
-
|
76 |
-
logits = outputs.logits
|
77 |
-
predictions = torch.argmax(logits, dim=-1)
|
78 |
-
metric.add_batch(predictions=predictions, references=batch["labels"])
|
79 |
-
|
80 |
-
metric.compute()
|
81 |
-
example_title: Example Three
|
82 |
- text: |
|
83 |
git lfs install
|
84 |
huggingface-cli lfs-enable-largefiles .
|
@@ -86,7 +20,7 @@ widget:
|
|
86 |
git add .
|
87 |
git commit -a -m "add fp32 chkpt"
|
88 |
git push
|
89 |
-
example_title:
|
90 |
- text: |
|
91 |
export interface DocumentParams {
|
92 |
pageContent: string;
|
@@ -109,12 +43,114 @@ widget:
|
|
109 |
this.metadata = fields?.metadata ?? {};
|
110 |
}
|
111 |
}
|
112 |
-
example_title:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
inference:
|
114 |
parameters:
|
115 |
max_length: 96
|
116 |
num_beams: 4
|
117 |
-
|
118 |
---
|
119 |
|
120 |
|
|
|
13 |
language:
|
14 |
- en
|
15 |
widget:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
- text: |
|
17 |
git lfs install
|
18 |
huggingface-cli lfs-enable-largefiles .
|
|
|
20 |
git add .
|
21 |
git commit -a -m "add fp32 chkpt"
|
22 |
git push
|
23 |
+
example_title: bash
|
24 |
- text: |
|
25 |
export interface DocumentParams {
|
26 |
pageContent: string;
|
|
|
43 |
this.metadata = fields?.metadata ?? {};
|
44 |
}
|
45 |
}
|
46 |
+
example_title: js
|
47 |
+
- text: |
|
48 |
+
def merge(left, right):
|
49 |
+
if len(left) == 0:
|
50 |
+
return right
|
51 |
+
|
52 |
+
if len(right) == 0:
|
53 |
+
return left
|
54 |
+
|
55 |
+
result = []
|
56 |
+
index_left = index_right = 0
|
57 |
+
|
58 |
+
while len(result) < len(left) + len(right):
|
59 |
+
if left[index_left] <= right[index_right]:
|
60 |
+
result.append(left[index_left])
|
61 |
+
index_left += 1
|
62 |
+
else:
|
63 |
+
result.append(right[index_right])
|
64 |
+
index_right += 1
|
65 |
+
|
66 |
+
if index_right == len(right):
|
67 |
+
result += left[index_left:]
|
68 |
+
break
|
69 |
+
|
70 |
+
if index_left == len(left):
|
71 |
+
result += right[index_right:]
|
72 |
+
break
|
73 |
+
|
74 |
+
return result
|
75 |
+
example_title: merge
|
76 |
+
- text: >
|
77 |
+
import pandas as pd
|
78 |
+
|
79 |
+
import plotly.graph_objects as go
|
80 |
+
|
81 |
+
|
82 |
+
df =
|
83 |
+
pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_apple_stock.csv')
|
84 |
+
|
85 |
+
|
86 |
+
fig = go.Figure(go.Scatter(x = df['AAPL_x'], y = df['AAPL_y'],
|
87 |
+
name='Share Prices (in USD)'))
|
88 |
+
|
89 |
+
fig.update_layout(title='Apple Share Prices over time (2014)',
|
90 |
+
plot_bgcolor='rgb(230, 230,230)',
|
91 |
+
showlegend=True)
|
92 |
+
|
93 |
+
fig.show()
|
94 |
+
example_title: plot
|
95 |
+
- text: |
|
96 |
+
from spellchecker import SpellChecker
|
97 |
+
|
98 |
+
spell = SpellChecker()
|
99 |
+
|
100 |
+
def check_word_spelling(word: str):
|
101 |
+
misspelled = spell.unknown([word])
|
102 |
+
return len(misspelled) == 0
|
103 |
+
|
104 |
+
def eval_and_replace(text: str, match_token: str = "- "):
|
105 |
+
if match_token not in text:
|
106 |
+
return text
|
107 |
+
else:
|
108 |
+
while True:
|
109 |
+
full_before_text = text.split(match_token, maxsplit=1)[0]
|
110 |
+
before_text = [
|
111 |
+
char for char in full_before_text.split()[-1] if char.isalpha()
|
112 |
+
]
|
113 |
+
before_text = "".join(before_text)
|
114 |
+
full_after_text = text.split(match_token, maxsplit=1)[-1]
|
115 |
+
after_text = [char for char in full_after_text.split()[0] if char.isalpha()]
|
116 |
+
after_text = "".join(after_text)
|
117 |
+
full_text = before_text + after_text
|
118 |
+
if check_word_spelling(full_text):
|
119 |
+
text = full_before_text + full_after_text
|
120 |
+
else:
|
121 |
+
text = full_before_text + " " + full_after_text
|
122 |
+
if match_token not in text:
|
123 |
+
break
|
124 |
+
return text
|
125 |
+
|
126 |
+
text = "I- am- a go- od- boy"
|
127 |
+
eval_and_replace(text)
|
128 |
+
example_title: speel check
|
129 |
+
- text: >
|
130 |
+
import torch
|
131 |
+
|
132 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
133 |
+
|
134 |
+
|
135 |
+
checkpoint = "distilbert-base-uncased-finetuned-sst-2-english"
|
136 |
+
|
137 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
138 |
+
|
139 |
+
model = AutoModelForSequenceClassification.from_pretrained(checkpoint)
|
140 |
+
|
141 |
+
sequences = ["I've been waiting for a HuggingFace course my whole life.",
|
142 |
+
"So have I!"]
|
143 |
+
|
144 |
+
|
145 |
+
tokens = tokenizer(sequences, padding=True, truncation=True,
|
146 |
+
return_tensors="pt")
|
147 |
+
|
148 |
+
output = model(**tokens)
|
149 |
+
example_title: model inference
|
150 |
inference:
|
151 |
parameters:
|
152 |
max_length: 96
|
153 |
num_beams: 4
|
|
|
154 |
---
|
155 |
|
156 |
|