-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
121 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
filename: | ||
test: test.json | ||
dev: dev.json | ||
config: config.yaml | ||
task_name: socialiqa |
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,66 @@ | ||
from typing import Optional | ||
import random | ||
# | ||
class InstanceCollection: | ||
def __init__(self) -> None: | ||
"""Initialize an empty collection of instances.""" | ||
self.instances = [] | ||
|
||
|
||
|
||
def __len__(self) -> int: | ||
"""Return the number of instances in the collection. | ||
Returns: | ||
int: The total number of instances in the collection. | ||
""" | ||
return len(self.instances) | ||
|
||
|
||
|
||
def __getitem__(self, index): | ||
"""Retrieve specific instance(s) by index or slice. | ||
Args: | ||
index (int or slice): The index of the instance to retrieve or a slice object to get a range of instances. | ||
Raises: | ||
IndexError: If the index is out of range. | ||
TypeError: If the provided index is not an int or slice. | ||
Returns: | ||
Instance or list of Instances: A single instance or a list of instances based on the provided index. | ||
""" | ||
if isinstance(index, int): | ||
if index >= len(self.instances) or index < 0: | ||
raise IndexError("Index out of range") | ||
return self.instances[index] | ||
elif isinstance(index, slice): | ||
return self.instances[index] | ||
else: | ||
raise TypeError("Invalid argument type") | ||
|
||
|
||
|
||
def sample( | ||
self, | ||
n: int, | ||
seed: Optional[int] = None | ||
) -> list: | ||
"""Randomly sample 'n' instances from the collection. | ||
Args: | ||
n (int): The number of instances to sample. | ||
seed (Optional[int]): Optional random seed for reproducibility. | ||
Raises: | ||
ValueError: If 'n' is greater than the total number of instances. | ||
Returns: | ||
list: A list of 'n' randomly sampled instances. | ||
""" | ||
if n > len(self.instances): | ||
raise ValueError("Sample size 'n' cannot be greater than the total number of instances.") | ||
if seed is not None: | ||
random.seed(seed) | ||
return random.sample(self.instances, n) |
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
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
# pip install -e . | ||
setup( | ||
name = 'nutcracker', | ||
version='0.0.1a2', | ||
version='0.0.1a3', | ||
description = 'In Development', | ||
author = 'Bruce W. Lee', | ||
author_email = '[email protected]', | ||
|