This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from emrgnt-cmplxty/feature/add-hugging-face-r…
…ebased2 Feature/add hugging face rebased2
- Loading branch information
Showing
9 changed files
with
704 additions
and
15 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
101 changes: 101 additions & 0 deletions
101
...thropic/leetcode/claude_2/anthropic_leetcode__model_eq_claude_2__temperature_eq_0p7.jsonl
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import torch | ||
import transformers | ||
from transformers import AutoTokenizer | ||
|
||
from zero_shot_replication.llm_providers.base import LLMProvider | ||
|
||
|
||
class HuggingFaceZeroShotProvider(LLMProvider): | ||
"""A class to provide zero-shot completions from the Anthropic API.""" | ||
|
||
MAX_TOKENS_TO_SAMPLE = ( | ||
4_096 # This is a large value, we should check if it makes sense | ||
) | ||
|
||
def __init__( | ||
self, | ||
model: str = "facebook/opt-125m", | ||
temperature: float = 0.7, | ||
stream: bool = False, | ||
) -> None: | ||
self.model = model | ||
self.temperature = temperature | ||
self.stream = stream | ||
self.tokenizer = AutoTokenizer.from_pretrained(self.model) | ||
|
||
self.pipeline = transformers.pipeline( | ||
"text-generation", | ||
model=self.model, | ||
torch_dtype=torch.float16, | ||
device_map="auto", | ||
) | ||
|
||
def get_completion(self, prompt: str) -> str: | ||
"""Get a completion from the Anthropic API based on the provided prompt.""" | ||
|
||
sequences = self.pipeline( | ||
'I liked "Breaking Bad" and "Band of Brothers". Do you have any recommendations of other shows I might like?\n', | ||
do_sample=True, | ||
top_k=10, | ||
num_return_sequences=1, | ||
eos_token_id=self.tokenizer.eos_token_id, | ||
max_length=HuggingFaceZeroShotProvider.MAX_TOKENS_TO_SAMPLE, | ||
) | ||
for seq in sequences: | ||
print(f"Result: {seq['generated_text']}") | ||
raise NotImplementedError( | ||
"HuggingFaceZeroShotProvider not implemented." | ||
) |
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