L
Initializing Studio...
Understand model types, architectures, and lifecycle management in LangTrain.
1import langtrain23client = langtrain.LangTrain()45# Text classification model6classifier = client.models.create(7 name="product-categorizer",8 type="text-classification",9 labels=["electronics", "clothing", "books", "home"],10 base_model="bert-base-uncased"11)1213# Text generation model14generator = client.models.create(15 name="content-writer",16 type="text-generation",17 base_model="gpt-3.5-turbo",18 max_length=51219)2021# NER model22ner_model = client.models.create(23 name="document-extractor",24 type="named-entity-recognition",25 entity_types=["PERSON", "ORG", "DATE", "MONEY"]26)
1# List all models2models = client.models.list()3for model in models:4 print(f"Model: {model.name} (v{model.version})")5 print(f"Type: {model.type}")6 print(f"Status: {model.status}")7 print("---")89# Get specific model10model = client.models.get("product-categorizer")1112# Update model metadata13model.update(14 description="Updated product categorization model",15 tags=["production", "v2.0"]16)1718# Clone model for experimentation19cloned_model = model.clone(20 name="product-categorizer-experiment",21 description="Experimental version with new architecture"22)
1# Compare model versions2comparison = client.models.compare(3 model_ids=["model-v1", "model-v2", "model-v3"],4 metrics=["accuracy", "f1_score", "latency"]5)67print("Model Comparison:")8for model_id, metrics in comparison.items():9 print(f"{model_id}:")10 for metric, value in metrics.items():11 print(f" {metric}: {value}")1213# Get best performing model14best_model = comparison.get_best(metric="f1_score")15print(f"Best model: {best_model.id}")1617# Deploy best model18deployment = best_model.deploy(19 name="production-classifier",20 auto_scale=True21)
1# Upload custom PyTorch model2import torch34# Your custom model class5class CustomClassifier(torch.nn.Module):6 def __init__(self, vocab_size, embed_dim, num_classes):7 super().__init__()8 self.embedding = torch.nn.Embedding(vocab_size, embed_dim)9 self.classifier = torch.nn.Linear(embed_dim, num_classes)1011 def forward(self, x):12 embedded = self.embedding(x).mean(dim=1)13 return self.classifier(embedded)1415# Upload to LangTrain16model = client.models.upload_custom(17 name="my-custom-model",18 model_class=CustomClassifier,19 model_path="./my_model.pth",20 tokenizer_path="./tokenizer.json",21 config={22 "vocab_size": 10000,23 "embed_dim": 128,24 "num_classes": 525 }26)