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

support for collection shuffle #3294

Merged
merged 2 commits into from
Nov 1, 2023
Merged

Conversation

colombod
Copy link
Member

@colombod colombod commented Nov 1, 2023

to go from

var rnd = new Random(42);

var examples = centroids.Select(c => {
    var embedding = c.GetValues().ToArray();
    var reviews = new LinkedList<DataRow>(foodReviewsData
        .ScoreBySimilarityTo(embedding, new CosineSimilarityComparer<float[]>(v => v), r => r.Embedding )
        .OrderByDescending(e => e.Value)
        .Select(e => e.Key)
        .Take(200));

    var samples = new List<DataRow>();
    for(var i = 0; i < 5; i++)
    {
        var sample = reviews.ElementAt(rnd.Next(reviews.Count));
        samples.Add(sample);
        reviews.Remove(sample);
    }
    return new {
            CenstroidEmbedding = embedding,
            Reviews = samples
            };
    }
).ToArray();

to

var examples = centroids.Select(c => {
    var embedding = c.GetValues().ToArray();
    var reviews = new LinkedList<DataRow>(foodReviewsData
        .ScoreBySimilarityTo(embedding, new CosineSimilarityComparer<float[]>(v => v), r => r.Embedding )
        .OrderByDescending(e => e.Value)
        .Select(e => e.Key)
        .Take(200)
        .Shuffle()
        .Take(5));

    return new {
            CenstroidEmbedding = embedding,
            Reviews = examples 
            };
    }
).ToArray();

can see more in the PR azure-samples/openai#63

@colombod colombod changed the title support for random order support for collection shuffle Nov 1, 2023
@colombod colombod enabled auto-merge (rebase) November 1, 2023 15:06
@colombod colombod merged commit 4ef8bbc into dotnet:main Nov 1, 2023
4 checks passed
@colombod colombod deleted the cookbook_support branch November 1, 2023 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants