Skip to content

Quote modelId in KerasHub snippets #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/tasks/src/model-libraries-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ const _keras_hub_causal_lm = (modelId: string): string => `
import keras_hub

# Load CausalLM model (optional: use half precision for inference)
causal_lm = keras_hub.models.CausalLM.from_preset(${modelId}, dtype="bfloat16")
causal_lm = keras_hub.models.CausalLM.from_preset("${modelId}", dtype="bfloat16")
causal_lm.compile(sampler="greedy") # (optional) specify a sampler

# Generate text
Expand All @@ -454,7 +454,7 @@ const _keras_hub_text_to_image = (modelId: string): string => `
import keras_hub

# Load TextToImage model (optional: use half precision for inference)
text_to_image = keras_hub.models.TextToImage.from_preset(${modelId}, dtype="bfloat16")
text_to_image = keras_hub.models.TextToImage.from_preset("${modelId}", dtype="bfloat16")

# Generate images with a TextToImage model.
text_to_image.generate("Astronaut in a jungle")
Expand All @@ -465,7 +465,7 @@ import keras_hub

# Load TextClassifier model
text_classifier = keras_hub.models.TextClassifier.from_preset(
${modelId},
"${modelId}",
num_classes=2,
)
# Fine-tune
Expand All @@ -480,7 +480,7 @@ import keras

# Load ImageClassifier model
image_classifier = keras_hub.models.ImageClassifier.from_preset(
${modelId},
"${modelId}",
num_classes=2,
)
# Fine-tune
Expand All @@ -503,14 +503,14 @@ const _keras_hub_task_without_example = (task: string, modelId: string): string
import keras_hub

# Create a ${task} model
task = keras_hub.models.${task}.from_preset(${modelId})
task = keras_hub.models.${task}.from_preset("${modelId}")
`;

const _keras_hub_generic_backbone = (modelId: string): string => `
import keras_hub

# Create a Backbone model unspecialized for any task
backbone = keras_hub.models.Backbone.from_preset(${modelId})
backbone = keras_hub.models.Backbone.from_preset("${modelId}")
`;

export const keras_hub = (model: ModelData): string[] => {
Expand Down
Loading