Close Menu
    Facebook X (Twitter) Instagram
    Articles Stock
    • Home
    • Technology
    • AI
    • Pages
      • About us
      • Contact us
      • Disclaimer For Articles Stock
      • Privacy Policy
      • Terms and Conditions
    Facebook X (Twitter) Instagram
    Articles Stock
    AI

    A Complete Implementation Information to ModelScope for Mannequin Search, Inference, High quality-Tuning, Analysis, and Export

    Naveed AhmadBy Naveed Ahmad09/04/2026Updated:09/04/2026No Comments2 Mins Read
    blog 17


    print("nπŸ“Š MODEL EVALUATIONn")
    
    
    eval_results = coach.consider()
    print("  Analysis Outcomes:")
    for key, worth in eval_results.objects():
       if isinstance(worth, float):
           print(f"    {key:<25}: {worth:.4f}")
    
    
    from sklearn.metrics import classification_report, confusion_matrix
    
    
    preds_output = coach.predict(eval_ds)
    preds = np.argmax(preds_output.predictions, axis=-1)
    labels = preds_output.label_ids
    
    
    print("n  Classification Report:")
    print(classification_report(labels, preds, target_names=["NEGATIVE", "POSITIVE"]))
    
    
    cm = confusion_matrix(labels, preds)
    fig, ax = plt.subplots(figsize=(5, 4))
    im = ax.imshow(cm, cmap="Blues")
    ax.set_xticks([0, 1]); ax.set_yticks([0, 1])
    ax.set_xticklabels(["NEGATIVE", "POSITIVE"])
    ax.set_yticklabels(["NEGATIVE", "POSITIVE"])
    ax.set_xlabel("Predicted"); ax.set_ylabel("Precise")
    ax.set_title("Confusion Matrix β€” High quality-Tuned DistilBERT")
    for i in vary(2):
       for j in vary(2):
           ax.textual content(j, i, str(cm[i, j]), ha="middle", va="middle",
                   coloration="white" if cm[i, j] > cm.max()/2 else "black", fontsize=18)
    plt.colorbar(im)
    plt.tight_layout()
    plt.savefig("confusion_matrix.png", dpi=150)
    plt.present()
    print("  βœ… Saved confusion_matrix.png")
    
    
    print("n── Testing High quality-Tuned Mannequin on New Inputs ──")
    ft_pipeline = hf_pipeline(
       "sentiment-analysis",
       mannequin=coach.mannequin,
       tokenizer=tokenizer,
       gadget=DEVICE,
    )
    
    
    new_reviews = [
       "An absolutely breathtaking masterpiece with brilliant performances!",
       "Waste of two hours. Terrible script and wooden acting.",
       "Decent popcorn movie but nothing special. Had some fun moments.",
    ]
    
    
    for evaluation in new_reviews:
       res = ft_pipeline(evaluation)[0]
       emoji = "🟒" if res["label"] == "POSITIVE" else "πŸ”΄"
       print(f'  {emoji} {res["label"]} ({res["score"]:.4f}): "{evaluation}"')
    
    
    
    
    print("nπŸ’Ύ EXPORTING THE FINE-TUNED MODELn")
    
    
    save_path = "./ms_finetuned_model/remaining"
    coach.save_model(save_path)
    tokenizer.save_pretrained(save_path)
    print(f"  βœ… Mannequin saved to: {save_path}")
    print(f"     Recordsdata: {os.listdir(save_path)}")
    
    
    print("n── ONNX Export ──")
    attempt:
       from optimum.exporters.onnx import main_export
       onnx_path = "./ms_finetuned_model/onnx"
       main_export(save_path, output=onnx_path, job="text-classification")
       print(f"  βœ… ONNX mannequin exported to: {onnx_path}")
       print(f"     Recordsdata: {os.listdir(onnx_path)}")
    besides Exception as e:
       print(f"  ⚠️  ONNX export skipped: {e}")
    
    
    print("""
    ── Add to ModelScope Hub (guide step) ──
    
    
     1. Get a token from https://modelscope.cn/my/myaccesstoken
     2. Run:
    
    
        from modelscope.hub.api import HubApi
        api = HubApi()
        api.login('YOUR_TOKEN')
        api.push_model(
            model_id='your-username/my-finetuned-distilbert',
            model_dir="./ms_finetuned_model/remaining",
        )
    """)
    
    
    print("""
    ╔══════════════════════════════════════════════════════════════════╗
    β•‘                   πŸŽ‰  TUTORIAL COMPLETE!  πŸŽ‰                    β•‘
    ╠══════════════════════════════════════════════════════════════════╣
    β•‘  βœ“ ModelScope Hub β€” search, browse & obtain fashions            β•‘
    β•‘  βœ“ MsDataset β€” load datasets from the ModelScope ecosystem      β•‘
    β•‘  βœ“ NLP pipelines β€” sentiment, NER, zero-shot, technology, masks  β•‘
    β•‘  βœ“ CV pipelines β€” picture classification, object detection, viz   β•‘
    β•‘  βœ“ HuggingFace interop β€” snapshot_download + Transformers       β•‘
    β•‘  βœ“ High quality-tuning β€” DistilBERT on IMDB with Coach API            β•‘
    β•‘  βœ“ Analysis β€” accuracy, F1, confusion matrix                  β•‘
    β•‘  βœ“ Export β€” native save, ONNX, Hub add                        β•‘
    β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
    """)



    Source link

    Naveed Ahmad

    Related Posts

    Google AI Analysis Introduces PaperOrchestra: A Multi-Agent Framework for Automated AI Analysis Paper Writing

    09/04/2026

    Anthropic’s New Product Goals to Deal with the Exhausting A part of Constructing AI Brokers

    09/04/2026

    A self-driving automotive in Texas hit and killed a mom duck, sparking neighborhood outrage

    09/04/2026
    Leave A Reply Cancel Reply

    Categories
    • AI
    Recent Comments
      Facebook X (Twitter) Instagram Pinterest
      © 2026 ThemeSphere. Designed by ThemeSphere.

      Type above and press Enter to search. Press Esc to cancel.