-
Notifications
You must be signed in to change notification settings - Fork 48
Laboratory work #4, Marina Mokina - 22FPL1 #175
Conversation
delete requirements
lab_4_fill_words_by_ngrams/main.py
Outdated
@@ -98,6 +134,35 @@ def run(self, seq_len: int, prompt: str) -> str: # type: ignore | |||
or if sequence has inappropriate length, | |||
or if methods used return None. | |||
""" | |||
if not (isinstance(seq_len, int) and seq_len > 0 | |||
and isinstance(prompt, str) and prompt): | |||
raise ValueError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, add some message to error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lab_4_fill_words_by_ngrams/main.py
Outdated
if not next_tokens: | ||
break | ||
|
||
sorted_dict = dict(sorted(list(next_tokens.items()), key=lambda x: (x[1], x[0]), reverse=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you actually need list to do sorting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lab_4_fill_words_by_ngrams/main.py
Outdated
@@ -28,6 +32,19 @@ def _tokenize(self, text: str) -> tuple[str, ...]: # type: ignore | |||
Raises: | |||
ValueError: In case of inappropriate type input argument or if input argument is empty. | |||
""" | |||
if not isinstance(text, str) or not text: | |||
raise ValueError('WordProcessor._tokenize: Incorrect input') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove WordProcessor._tokenize
from the message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lab_4_fill_words_by_ngrams/main.py
Outdated
|
||
tokens = [] | ||
for word in text.lower().split(): | ||
if word[-1] in '!?.': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'!?.'
to a variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lab_4_fill_words_by_ngrams/main.py
Outdated
@@ -125,6 +195,8 @@ def get_conversion_generator_type(self, generator_type: int) -> str: # type: ig | |||
Returns: | |||
(str): Name of the generator. | |||
""" | |||
generators = ['Greedy Generator', 'Top-P Generator', 'Beam Search Generator'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if generator_type
is 4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lab_4_fill_words_by_ngrams/main.py
Outdated
for i in range(seq_len): | ||
next_tokens = self._model.generate_next_token(encoded) | ||
if next_tokens is None: | ||
raise ValueError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lab_4_fill_words_by_ngrams/main.py
Outdated
|
||
decoded = self._word_processor.decode(encoded) | ||
if not decoded: | ||
raise ValueError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lab_4_fill_words_by_ngrams/main.py
Outdated
@@ -125,6 +196,12 @@ def get_conversion_generator_type(self, generator_type: int) -> str: # type: ig | |||
Returns: | |||
(str): Name of the generator. | |||
""" | |||
types = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to init
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Well done! Good job! |
No description provided.