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

Key error on Week1 #30

Open
treblenalto opened this issue Feb 4, 2022 · 2 comments
Open

Key error on Week1 #30

treblenalto opened this issue Feb 4, 2022 · 2 comments

Comments

@treblenalto
Copy link

Hi @graviraja,
I was following your tutorial on wandb logging and found a potential error in the training code when visualizing poorly performed data with wandb table.

def on_validation_end(self, trainer, pl_module):
val_batch = next(iter(self.datamodule.val_dataloader()))
sentences = val_batch["sentence"]

When running, this results in KeyError : "sentence", referring to line 21 sentences = val_batch["sentence"].

I think this is because "sentence" is not part of the columns setup in val_data of data.py. Please correct me if I'm wrong. Thanks :)

def setup(self, stage=None):
# we set up only relevant datasets when stage is specified
if stage == "fit" or stage is None:
self.train_data = self.train_data.map(self.tokenize_data, batched=True)
self.train_data.set_format(
type="torch", columns=["input_ids", "attention_mask", "label"]
)
self.val_data = self.val_data.map(self.tokenize_data, batched=True)
self.val_data.set_format(
type="torch",
columns=["input_ids", "attention_mask", "label"],
output_all_columns=True,
)

@PTson2207
Copy link

Hi @Taehee-K ,
I also got the same error as you. Did you fix that error?
Can you show me the results?

@agamemnonc
Copy link

The solution to this is just to also include sentence in your data batching:

self.train_data.set_format( 
             type="torch", columns=["input_ids", "attention_mask", "label", "sentence"] 

and the same obviously for self.val_data.set_format() and self.test_data.set_format().

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

No branches or pull requests

3 participants