Skip to content
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

Add phi-1_5 model #493

Merged
merged 1 commit into from
Jan 2, 2024
Merged

Add phi-1_5 model #493

merged 1 commit into from
Jan 2, 2024

Conversation

xenova
Copy link
Collaborator

@xenova xenova commented Jan 2, 2024

closes #492. Converted model: Xenova/phi-1_5_dev (from susnato/phi-1_5_dev, which is the transformers-compatible version of microsoft/phi-1_5)

Example: Text generation (code completion) with Xenova/phi-1_5_dev.

import { pipeline } from '@xenova/transformers';

// Create a text-generation pipeline
const generator = await pipeline('text-generation', 'Xenova/phi-1_5_dev');

// Construct prompt
const prompt = `\`\`\`py
import math
def print_prime(n):
    """
    Print all primes between 1 and n
    """`;

// Generate text
const result = await generator(prompt, {
  max_new_tokens: 100,
});
console.log(result[0].generated_text);

Results in:

import math
def print_prime(n):
    """
    Print all primes between 1 and n
    """
    primes = []
    for num in range(2, n+1):
        is_prime = True
        for i in range(2, int(math.sqrt(num))+1):
            if num % i == 0:
                is_prime = False
                break
        if is_prime:
            primes.append(num)
    print(primes)

print_prime(20)

Running the code produces the correct result:

[2, 3, 5, 7, 11, 13, 17, 19]

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@xenova xenova merged commit 81f1e5c into main Jan 2, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for the phi-1.5 model in transformers.js
2 participants