L
Initializing Studio...
Understand model types, architectures, and lifecycle management in LangTrain.
import langtrain
client = langtrain.LangTrain()
# Text classification model
classifier = client.models.create(
name="product-categorizer",
type="text-classification",
labels=["electronics", "clothing", "books", "home"],
base_model="bert-base-uncased"
)
# Text generation model
generator = client.models.create(
name="content-writer",
type="text-generation",
base_model="gpt-3.5-turbo",
max_length=512
)
# NER model
ner_model = client.models.create(
name="document-extractor",
type="named-entity-recognition",
entity_types=["PERSON", "ORG", "DATE", "MONEY"]
)# List all models
models = client.models.list()
for model in models:
print(f"Model: {model.name} (v{model.version})")
print(f"Type: {model.type}")
print(f"Status: {model.status}")
print("---")
# Get specific model
model = client.models.get("product-categorizer")
# Update model metadata
model.update(
description="Updated product categorization model",
tags=["production", "v2.0"]
)
# Clone model for experimentation
cloned_model = model.clone(
name="product-categorizer-experiment",
description="Experimental version with new architecture"
)# Compare model versions
comparison = client.models.compare(
model_ids=["model-v1", "model-v2", "model-v3"],
metrics=["accuracy", "f1_score", "latency"]
)
print("Model Comparison:")
for model_id, metrics in comparison.items():
print(f"{model_id}:")
for metric, value in metrics.items():
print(f" {metric}: {value}")
# Get best performing model
best_model = comparison.get_best(metric="f1_score")
print(f"Best model: {best_model.id}")
# Deploy best model
deployment = best_model.deploy(
name="production-classifier",
auto_scale=True
)# Upload custom PyTorch model
import torch
# Your custom model class
class CustomClassifier(torch.nn.Module):
def __init__(self, vocab_size, embed_dim, num_classes):
super().__init__()
self.embedding = torch.nn.Embedding(vocab_size, embed_dim)
self.classifier = torch.nn.Linear(embed_dim, num_classes)
def forward(self, x):
embedded = self.embedding(x).mean(dim=1)
return self.classifier(embedded)
# Upload to LangTrain
model = client.models.upload_custom(
name="my-custom-model",
model_class=CustomClassifier,
model_path="./my_model.pth",
tokenizer_path="./tokenizer.json",
config={
"vocab_size": 10000,
"embed_dim": 128,
"num_classes": 5
}
)