Microsoft’s Phi-3 Models: A Game Changer in AI Performance and Accessibility
    Deep Dives

    Microsoft’s Phi-3 Models: A Game Changer in AI Performance and Accessibility

    Microsoft’s Phi-3 small and medium models, released under the MIT license, set new performance benchmarks, outperforming major competitors and enhancing AI accessibility.

    ADaSci Editorial
    ADaSci EditorialEditorial Team, Association of Data Scientists
    May 25, 2024

    Microsoft has taken a significant leap in the AI landscape by releasing the Phi-3 small (7B) and medium (14B) models under the MIT license. These models promise to set new benchmarks in performance, challenging giants like Meta’s Llama 3 and OpenAI’s GPT-3.5. Let’s delve into what makes these models stand out and how they can be utilized effectively.

    Key Highlights of Phi-3 Models

    1. Model Specifications:
    2. Phi-3 Small (7B): 75.5 on MMLU and 43.9 on AGI Eval, outperforming Mistral 7B and Llama 3 8B.
    3. Phi-3 Medium (14B): 78.0 on MMLU and 50.2 on AGI Eval, surpassing GPT-3.5-Turbo and Cohere Command R+.
    4. Training and Performance:
    5. Trained on 4.8 trillion tokens, including synthetic and filtered public datasets with multilingual support.
    6. Fine-tuned using Supervised Fine-Tuning (SFT) and Direct Preference Optimization (DPO).
    7. New tokenizer with a vocabulary size of 100,352.
    8. Availability:
    9. Available on platforms like HuggingFace, Azure AI, and ONNX, making them accessible to a broad range of developers and researchers.

    The Power of Context: Up to 128k Tokens

    Both Phi-3 models support context lengths of up to 128k tokens, which significantly enhances their capability to handle extensive and complex tasks. This makes them ideal for applications requiring long-term context understanding and large-scale data processing.

    Practical Applications and Code Snippets

    Here’s how you can quickly get started with the Phi-3 small model for text generation using the HuggingFace Transformers library:

    pythonCopy codeimport torch
    from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

    # Ensure you have the necessary packages
    # !pip install transformers torch

    model_id = "microsoft/Phi-3-small-128k-instruct"
    model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype="auto",
    trust_remote_code=True
    )
    device = torch.cuda.current_device() if torch.cuda.is_available() else "cpu"
    model = model.to(device)
    tokenizer = AutoTokenizer.from_pretrained(model_id)

    # Define your prompts
    messages = [
    {"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
    {"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
    {"role": "user", "content": "What about solving a 2x + 3 = 7 equation?"}
    ]

    # Setup the pipeline
    pipe = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    device=device
    )

    # Generate responses
    generation_args = {
    "max_new_tokens": 500,
    "return_full_text": False,
    "temperature": 0.0,
    "do_sample": False
    }
    output = pipe(messages, **generation_args)
    print(output[0]['generated_text'])

    This snippet demonstrates the ease of integrating the Phi-3 model into your applications, allowing for efficient and effective AI-driven solutions.

    Considerations and Best Practices

    While these models open up numerous possibilities, it’s essential to implement responsible AI practices:

    1. Quality of Service: Primarily trained on English text; performance may vary for other languages.
    2. Representation and Bias: Be aware of potential biases in the data and model outputs.
    3. Inappropriate Content: Implement safety measures to filter and mitigate harmful content.
    4. Legal Compliance: Ensure usage complies with relevant laws and regulations.

    Conclusion

    Microsoft’s Phi-3 small and medium models, with their advanced capabilities and accessibility, are poised to revolutionize the landscape of AI applications. Whether you are developing AI-driven chatbots, engaging in complex data analysis, or creating interactive applications, these models provide a robust foundation for innovation and development. With their release under the MIT license, the barrier to entry is significantly lowered, allowing a broader community to harness their potential.

    Explore these models and integrate them into your projects to experience the cutting-edge advancements in AI technology.

    Links to the models:

    1. Phi-3 small 128k
    2. Phi-3 medium 128k
    3. Phi-3 small 8k
    4. Phi-3 medium 4k


    adasci-editorial

    ADaSci Editorial

    The ADaSci Editorial team publishes research explainers, industry analysis and practical guides for AI and data science professionals.