forked from instructlab/sdg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporate knowledge generation context selection improvements
This incorporates fixes from aakankshaduggal#21 to the way we select the expanded contexts during the knowledge data generation, cleaning up the logic around how we select which other documents to include in the expanded context during edge cases where we have low numbers of unique documents Co-authored-by: abhi1092 <[email protected]> Signed-off-by: Ben Browning <[email protected]>
- Loading branch information
Showing
2 changed files
with
95 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Unit tests for the top-level datamixing module. | ||
""" | ||
|
||
# Third Party | ||
from datasets import Dataset | ||
|
||
# First Party | ||
from instructlab.sdg.datamixing import _add_extra_contexts_to_samples | ||
|
||
|
||
def _fake_context(msg_id): | ||
return { | ||
"context": f"context {msg_id}", | ||
"id": msg_id, | ||
"messages": [{"role": "user", "content": f"user content {msg_id}"}], | ||
"metadata": '{"dataset": []}', | ||
} | ||
|
||
|
||
def test_add_extra_contexts_to_samples_with_one_sample(): | ||
""" | ||
Test _add_extra_contexts_to_samples doesn't error out when | ||
given only one sample | ||
""" | ||
samples = Dataset.from_list([_fake_context("abc123")]) | ||
dataset = _add_extra_contexts_to_samples(samples, p=0.4) | ||
assert len(dataset) == 1 | ||
|
||
|
||
def test_add_extra_contexts_to_samples_with_two_samples(): | ||
""" | ||
Test _add_extra_contexts_to_samples doesn't error out when | ||
given only two samples | ||
""" | ||
samples = Dataset.from_list( | ||
[ | ||
_fake_context("abc123"), | ||
_fake_context("bcd234"), | ||
] | ||
) | ||
dataset = _add_extra_contexts_to_samples(samples, p=0.4) | ||
assert len(dataset) == 2 | ||
|
||
|
||
def test_add_extra_contexts_to_samples_with_six_samples(): | ||
""" | ||
Test _add_extra_contexts_to_samples doesn't error out when | ||
given more samples | ||
""" | ||
samples = Dataset.from_list( | ||
[ | ||
_fake_context("s1"), | ||
_fake_context("s2"), | ||
_fake_context("s3"), | ||
_fake_context("s4"), | ||
_fake_context("s5"), | ||
_fake_context("s6"), | ||
] | ||
) | ||
dataset = _add_extra_contexts_to_samples(samples, p=0.4) | ||
assert len(dataset) == 6 |