Update README.md
Browse files
README.md
CHANGED
|
@@ -12,6 +12,92 @@ metrics:
|
|
| 12 |
- rouge
|
| 13 |
language:
|
| 14 |
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
inference:
|
| 16 |
parameters:
|
| 17 |
max_length: 128
|
|
|
|
| 12 |
- rouge
|
| 13 |
language:
|
| 14 |
- en
|
| 15 |
+
examples:
|
| 16 |
+
- text: |
|
| 17 |
+
import torch
|
| 18 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 19 |
+
|
| 20 |
+
checkpoint = "distilbert-base-uncased-finetuned-sst-2-english"
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
| 22 |
+
model = AutoModelForSequenceClassification.from_pretrained(checkpoint)
|
| 23 |
+
sequences = ["I've been waiting for a HuggingFace course my whole life.", "So have I!"]
|
| 24 |
+
|
| 25 |
+
tokens = tokenizer(sequences, padding=True, truncation=True, return_tensors="pt")
|
| 26 |
+
output = model(**tokens)
|
| 27 |
+
example_title: Example One
|
| 28 |
+
|
| 29 |
+
- text: |
|
| 30 |
+
import torch
|
| 31 |
+
from tqdm.auto import tqdm
|
| 32 |
+
|
| 33 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
| 34 |
+
model.to(device)
|
| 35 |
+
|
| 36 |
+
progress_bar = tqdm(range(num_training_steps))
|
| 37 |
+
|
| 38 |
+
model.train()
|
| 39 |
+
for epoch in range(num_epochs):
|
| 40 |
+
for batch in train_dataloader:
|
| 41 |
+
batch = {k: v.to(device) for k, v in batch.items()}
|
| 42 |
+
outputs = model(**batch)
|
| 43 |
+
loss = outputs.loss
|
| 44 |
+
loss.backward()
|
| 45 |
+
|
| 46 |
+
optimizer.step()
|
| 47 |
+
lr_scheduler.step()
|
| 48 |
+
optimizer.zero_grad()
|
| 49 |
+
progress_bar.update(1)
|
| 50 |
+
example_title: Example Two
|
| 51 |
+
|
| 52 |
+
- text: |
|
| 53 |
+
import evaluate
|
| 54 |
+
|
| 55 |
+
metric = evaluate.load("glue", "mrpc")
|
| 56 |
+
model.eval()
|
| 57 |
+
for batch in eval_dataloader:
|
| 58 |
+
batch = {k: v.to(device) for k, v in batch.items()}
|
| 59 |
+
with torch.no_grad():
|
| 60 |
+
outputs = model(**batch)
|
| 61 |
+
|
| 62 |
+
logits = outputs.logits
|
| 63 |
+
predictions = torch.argmax(logits, dim=-1)
|
| 64 |
+
metric.add_batch(predictions=predictions, references=batch["labels"])
|
| 65 |
+
|
| 66 |
+
metric.compute()
|
| 67 |
+
example_title: Example Three
|
| 68 |
+
|
| 69 |
+
- text: |
|
| 70 |
+
git lfs install
|
| 71 |
+
huggingface-cli lfs-enable-largefiles .
|
| 72 |
+
git lfs track "*.bin"
|
| 73 |
+
git add .
|
| 74 |
+
git commit -a -m "add fp32 chkpt"
|
| 75 |
+
git push
|
| 76 |
+
example_title: Example Four
|
| 77 |
+
|
| 78 |
+
- text: |
|
| 79 |
+
export interface DocumentParams {
|
| 80 |
+
pageContent: string;
|
| 81 |
+
|
| 82 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 83 |
+
metadata: Record<string, any>;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* Interface for interacting with a document.
|
| 88 |
+
*/
|
| 89 |
+
export class Document implements DocumentParams {
|
| 90 |
+
pageContent: string;
|
| 91 |
+
|
| 92 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 93 |
+
metadata: Record<string, any>;
|
| 94 |
+
|
| 95 |
+
constructor(fields?: Partial<DocumentParams>) {
|
| 96 |
+
this.pageContent = fields?.pageContent ?? this.pageContent;
|
| 97 |
+
this.metadata = fields?.metadata ?? {};
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
example_title: Example Five
|
| 101 |
inference:
|
| 102 |
parameters:
|
| 103 |
max_length: 128
|