-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #3
base: master
Are you sure you want to change the base?
Conversation
if len(keyword_sentence_mapping.keys()) == 0: | ||
return final_output | ||
else: | ||
if len(keyword_sentence_mapping.keys()) != 0: |
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.
Function QGen.predict_mcq
refactored with the following changes:
- Hoist nested repeated code outside conditional statements (
hoist-similar-statement-from-if
)
self.text = "paraphrase: " + self.sentence + " </s>" | ||
self.text = f"paraphrase: {self.sentence} </s>" |
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.
Function QGen.paraphrase
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
) - Merge dictionary assignment with declaration [×3] (
merge-dict-assign
) - Replace call to format with f-string (
use-fstring-for-formatting
)
form = "truefalse: %s passage: %s </s>" % (modified_text, answer) | ||
form = f"truefalse: {modified_text} passage: {answer} </s>" |
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.
Function BoolQGen.predict_boolq
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Merge dictionary assignment with declaration [×3] (
merge-dict-assign
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
def greedy_decoding(inp_ids, attn_mask, model, tokenizer): | ||
greedy_output = model.generate(input_ids=inp_ids, attention_mask=attn_mask, max_length=256) | ||
def greedy_decoding(self, attn_mask, model, tokenizer): | ||
greedy_output = model.generate( | ||
input_ids=self, attention_mask=attn_mask, max_length=256 | ||
) | ||
|
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.
Function AnswerPredictor.greedy_decoding
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
input = "question: %s <s> context: %s </s>" % (question, context) | ||
input = f"question: {question} <s> context: {context} </s>" | ||
|
||
encoding = self.tokenizer.encode_plus(input, return_tensors="pt") | ||
input_ids, attention_masks = encoding["input_ids"].to(self.device), encoding["attention_mask"].to(self.device) | ||
greedy_output = self.model.generate(input_ids=input_ids, attention_mask=attention_masks, max_length=256) | ||
Question = self.tokenizer.decode(greedy_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=True) | ||
output = Question.strip().capitalize() | ||
|
||
return output | ||
return Question.strip().capitalize() |
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.
Function AnswerPredictor.predict_answer
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
"params": [p for n, p in model.named_parameters() if not any(nd in n for nd in no_decay)], | ||
"params": [ | ||
p | ||
for n, p in model.named_parameters() | ||
if all(nd not in n for nd in no_decay) | ||
], | ||
"weight_decay": self.hparams.weight_decay, | ||
}, | ||
{ | ||
"params": [p for n, p in model.named_parameters() if any(nd in n for nd in no_decay)], | ||
"params": [ | ||
p | ||
for n, p in model.named_parameters() | ||
if any(nd in n for nd in no_decay) | ||
], | ||
"weight_decay": 0.0, | ||
}, | ||
] | ||
|
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.
Function T5FineTuner.configure_optimizers
refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all
)
tqdm_dict = {"loss": "{:.3f}".format(self.trainer.avg_loss), "lr": self.lr_scheduler.get_last_lr()[-1]} | ||
|
||
return tqdm_dict | ||
return { | ||
"loss": "{:.3f}".format(self.trainer.avg_loss), | ||
"lr": self.lr_scheduler.get_last_lr()[-1], | ||
} |
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.
Function T5FineTuner.get_tqdm_dict
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
logger.info("{} = {}\n".format(key, str(metrics[key]))) | ||
logger.info(f"{key} = {str(metrics[key])}\n") |
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.
Function LoggingCallback.on_validation_end
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
logger.info("{} = {}\n".format(key, str(metrics[key]))) | ||
writer.write("{} = {}\n".format(key, str(metrics[key]))) | ||
logger.info(f"{key} = {str(metrics[key])}\n") | ||
writer.write(f"{key} = {str(metrics[key])}\n") |
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.
Function LoggingCallback.on_test_end
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
self.data.loc[idx, self.target_column] | ||
self.data.loc[idx, self.target_column] | ||
true_false = str(true_false) | ||
if true_false.lower() == "true": | ||
true_false = "yes" | ||
else: | ||
true_false = "no" | ||
true_false = "yes" if true_false.lower() == "true" else "no" | ||
# input_ = "paraphrase: "+ input_ + ' </s>' | ||
input_ = "truefalse: %s passage: %s </s>" % (true_false, passage) | ||
input_ = f"truefalse: {true_false} passage: {passage} </s>" |
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.
Function BooleanDataset._build
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.62%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!