Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Laboratory work #4, Marina Mokina - 22FPL1 #175

Closed
wants to merge 102 commits into from

Conversation

mmarina2004
Copy link

No description provided.

@@ -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
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if not next_tokens:
break

sorted_dict = dict(sorted(list(next_tokens.items()), key=lambda x: (x[1], x[0]), reverse=True))
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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')
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


tokens = []
for word in text.lower().split():
if word[-1] in '!?.':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'!?.' to a variable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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']
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

for i in range(seq_len):
next_tokens = self._model.generate_next_token(encoded)
if next_tokens is None:
raise ValueError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


decoded = self._word_processor.decode(encoded)
if not decoded:
raise ValueError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -125,6 +196,12 @@ def get_conversion_generator_type(self, generator_type: int) -> str: # type: ig
Returns:
(str): Name of the generator.
"""
types = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to init

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@vitazaytseva
Copy link

Well done! Good job!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants