Skip to content

Commit e608ac0

Browse files
committed
finetune example in snippet
1 parent 20d88bb commit e608ac0

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

packages/tasks/src/model-libraries-snippets.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,20 +419,32 @@ const _keras_hub_text_classifier = (modelId: string): string => `
419419
import keras_hub
420420
421421
# Load TextClassifier model
422-
text_classifier = keras_hub.models.TextClassifier.from_preset(${modelId})
423-
422+
text_classifier = keras_hub.models.TextClassifier.from_preset(
423+
${modelId},
424+
num_classes=2,
425+
)
426+
# Fine-tune
427+
text_classifier.fit(x=["Thilling adventure!", "Total snoozefest."], y=[1, 0])
424428
# Classify text
425-
text_classifier.predict("Keras is a multi-backend ML framework.")
429+
text_classifier.predict(["Not my cup of tea."])
426430
`;
427431

428432
const _keras_hub_image_classifier = (modelId: string): string => `
429433
import keras_hub
434+
import keras
430435
431436
# Load ImageClassifier model
432-
image_classifier = keras_hub.models.ImageClassifier.from_preset(${modelId})
433-
437+
image_classifier = keras_hub.models.ImageClassifier.from_preset(
438+
${modelId},
439+
num_classes=2,
440+
)
441+
# Fine-tune
442+
image_classifier.fit(
443+
x=keras.random.randint((32, 64, 64, 3), 0, 256),
444+
y=keras.random.randint((32, 1), 0, 2),
445+
)
434446
# Classify image
435-
image_classifier.predict(keras.ops.ones((1, 64, 64, 3)))
447+
image_classifier.predict(keras.random.randint((1, 64, 64, 3), 0, 256))
436448
`;
437449

438450
const _keras_hub_tasks_with_example = {

0 commit comments

Comments
 (0)