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

Do not fit transformers on testing data #3818

Closed
suhaibmujahid opened this issue Nov 16, 2023 · 2 comments · Fixed by #3877
Closed

Do not fit transformers on testing data #3818

suhaibmujahid opened this issue Nov 16, 2023 · 2 comments · Fixed by #3877
Assignees

Comments

@suhaibmujahid
Copy link
Member

Currently, we fit the transformers before splitting the data, which could leak testing data into the training data, especially when using something like TF-IDF in the extraction pipeline:

Transforming:

X = self.extraction_pipeline.fit_transform(X_gen)

Splitting:
X_train, X_test, y_train, y_test = self.train_test_split(X, y)

@suhaibmujahid suhaibmujahid self-assigned this Nov 16, 2023
@suhaibmujahid
Copy link
Member Author

Moving transformers that require fitting to the clf pipeline could fix the leaking issue:

self.clf = Pipeline(
[
(
"tokenizer",
HuggingfacePretrainedTokenizer(
"distilbert-base-uncased", max_length=512
),
),
(
"classifier",
NeuralNetClassifier(
DistilBertModule,
module__name="distilbert-base-uncased",
module__num_labels=2,
module__last_layer_only=last_layer_only,
optimizer=torch.optim.AdamW,
lr=6e-5,
max_epochs=2,
criterion=nn.CrossEntropyLoss,
batch_size=4,
iterator_train__shuffle=True,
device=get_training_device(),
callbacks=[
ProgressBar(),
],
),
),
]
)

However, with this solution, the extraction pipeline can no longer be treated as a transformers pipeline (transformers should support fit and transform).

@suhaibmujahid
Copy link
Member Author

The ideal solution for now will be to have two pipelines, one for extracting, and one for transforming. The extraction pipeline should not allow using fit().

@suhaibmujahid suhaibmujahid changed the title Split the data into training and testing before fitting the transformers Do not fit transformers on testing data Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant