Divyasreepat
commited on
Commit
•
93c0217
1
Parent(s):
07318b4
Update README.md with new model card content
Browse files
README.md
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
---
|
2 |
-
library_name: keras-hub
|
3 |
-
---
|
4 |
### Model Overview
|
5 |
A RoBERTa encoder network.
|
6 |
|
@@ -39,7 +36,7 @@ __Arguments__
|
|
39 |
### Example Usage
|
40 |
```python
|
41 |
import keras
|
42 |
-
import
|
43 |
import numpy as np
|
44 |
```
|
45 |
|
@@ -49,8 +46,8 @@ features = ["The quick brown fox jumped.", "I forgot my homework."]
|
|
49 |
labels = [0, 3]
|
50 |
|
51 |
# Pretrained classifier.
|
52 |
-
classifier =
|
53 |
-
"
|
54 |
num_classes=4,
|
55 |
)
|
56 |
classifier.fit(x=features, y=labels, batch_size=2)
|
@@ -77,10 +74,60 @@ features = {
|
|
77 |
labels = [0, 3]
|
78 |
|
79 |
# Pretrained classifier without preprocessing.
|
80 |
-
classifier =
|
81 |
-
"
|
82 |
num_classes=4,
|
83 |
preprocessor=None,
|
84 |
)
|
85 |
classifier.fit(x=features, y=labels, batch_size=2)
|
86 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
### Model Overview
|
2 |
A RoBERTa encoder network.
|
3 |
|
|
|
36 |
### Example Usage
|
37 |
```python
|
38 |
import keras
|
39 |
+
import keras_nlp
|
40 |
import numpy as np
|
41 |
```
|
42 |
|
|
|
46 |
labels = [0, 3]
|
47 |
|
48 |
# Pretrained classifier.
|
49 |
+
classifier = keras_nlp.models.RobertaClassifier.from_preset(
|
50 |
+
"${VARIATION_SLUG}",
|
51 |
num_classes=4,
|
52 |
)
|
53 |
classifier.fit(x=features, y=labels, batch_size=2)
|
|
|
74 |
labels = [0, 3]
|
75 |
|
76 |
# Pretrained classifier without preprocessing.
|
77 |
+
classifier = keras_nlp.models.RobertaClassifier.from_preset(
|
78 |
+
"${VARIATION_SLUG}",
|
79 |
num_classes=4,
|
80 |
preprocessor=None,
|
81 |
)
|
82 |
classifier.fit(x=features, y=labels, batch_size=2)
|
83 |
+
```
|
84 |
+
|
85 |
+
## Example Usage with HuggingFace uri
|
86 |
+
|
87 |
+
```python
|
88 |
+
import keras
|
89 |
+
import keras_nlp
|
90 |
+
import numpy as np
|
91 |
+
```
|
92 |
+
|
93 |
+
Raw string data.
|
94 |
+
```python
|
95 |
+
features = ["The quick brown fox jumped.", "I forgot my homework."]
|
96 |
+
labels = [0, 3]
|
97 |
+
|
98 |
+
# Pretrained classifier.
|
99 |
+
classifier = keras_nlp.models.RobertaClassifier.from_preset(
|
100 |
+
"${VARIATION_SLUG}",
|
101 |
+
num_classes=4,
|
102 |
+
)
|
103 |
+
classifier.fit(x=features, y=labels, batch_size=2)
|
104 |
+
classifier.predict(x=features, batch_size=2)
|
105 |
+
|
106 |
+
# Re-compile (e.g., with a new learning rate).
|
107 |
+
classifier.compile(
|
108 |
+
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
|
109 |
+
optimizer=keras.optimizers.Adam(5e-5),
|
110 |
+
jit_compile=True,
|
111 |
+
)
|
112 |
+
# Access backbone programmatically (e.g., to change `trainable`).
|
113 |
+
classifier.backbone.trainable = False
|
114 |
+
# Fit again.
|
115 |
+
classifier.fit(x=features, y=labels, batch_size=2)
|
116 |
+
```
|
117 |
+
|
118 |
+
Preprocessed integer data.
|
119 |
+
```python
|
120 |
+
features = {
|
121 |
+
"token_ids": np.ones(shape=(2, 12), dtype="int32"),
|
122 |
+
"padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
|
123 |
+
}
|
124 |
+
labels = [0, 3]
|
125 |
+
|
126 |
+
# Pretrained classifier without preprocessing.
|
127 |
+
classifier = keras_nlp.models.RobertaClassifier.from_preset(
|
128 |
+
"${VARIATION_SLUG}",
|
129 |
+
num_classes=4,
|
130 |
+
preprocessor=None,
|
131 |
+
)
|
132 |
+
classifier.fit(x=features, y=labels, batch_size=2)
|
133 |
+
```
|