Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Oct 13, 2022

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:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from devzer01 October 13, 2022 18:10
if len(keyword_sentence_mapping.keys()) == 0:
return final_output
else:
if len(keyword_sentence_mapping.keys()) != 0:
Copy link
Author

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:

Comment on lines -124 to +122
self.text = "paraphrase: " + self.sentence + " </s>"
self.text = f"paraphrase: {self.sentence} </s>"
Copy link
Author

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:

Comment on lines -194 to +193
form = "truefalse: %s passage: %s </s>" % (modified_text, answer)
form = f"truefalse: {modified_text} passage: {answer} </s>"
Copy link
Author

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:

Comment on lines -229 to +227
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
)

Copy link
Author

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:

Comment on lines -243 to +246
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()
Copy link
Author

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:

Comment on lines -94 to +108
"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,
},
]

Copy link
Author

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:

Comment on lines -115 to +125
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],
}
Copy link
Author

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:

Comment on lines -150 to +158
logger.info("{} = {}\n".format(key, str(metrics[key])))
logger.info(f"{key} = {str(metrics[key])}\n")
Copy link
Author

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:

Comment on lines -163 to +172
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")
Copy link
Author

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:

Comment on lines -231 to +243
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>"
Copy link
Author

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:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Oct 13, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.62%.

Quality metrics Before After Change
Complexity 2.77 ⭐ 2.42 ⭐ -0.35 👍
Method Length 73.58 🙂 72.14 🙂 -1.44 👍
Working memory 7.38 🙂 7.44 🙂 0.06 👎
Quality 72.08% 🙂 72.70% 🙂 0.62% 👍
Other metrics Before After Change
Lines 754 738 -16
Changed files Quality Before Quality After Quality Change
questgen/main.py 72.36% 🙂 72.31% 🙂 -0.05% 👎
questgen/mcq/mcq.py 65.77% 🙂 66.76% 🙂 0.99% 👍
questgen/train/train_gpu.py 80.34% ⭐ 80.34% ⭐ 0.00%

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
questgen/mcq/mcq.py generate_questions_mcq 4 ⭐ 242 ⛔ 13 😞 46.52% 😞 Try splitting into smaller methods. Extract out complex expressions
questgen/main.py QGen.paraphrase 6 ⭐ 209 ⛔ 8 🙂 56.08% 🙂 Try splitting into smaller methods
questgen/mcq/mcq.py generate_normal_questions 2 ⭐ 179 😞 11 😞 56.22% 🙂 Try splitting into smaller methods. Extract out complex expressions
questgen/mcq/mcq.py sense2vec_get_words 4 ⭐ 147 😞 9 🙂 61.32% 🙂 Try splitting into smaller methods
questgen/main.py QGen.predict_mcq 5 ⭐ 120 😞 10 😞 61.42% 🙂 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

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

Successfully merging this pull request may close these issues.

0 participants