Skip to content

Commit

Permalink
Updates for transformers v4.31.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ThilinaRajapakse committed Aug 3, 2023
1 parent 365b27f commit 12feed2
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.64.0] - 2023-04-24

### Changed

- Updates for compatibility with transformers v4.31.0

### Fixed

- Fixed bug in `ClassificationModel` when using `sliding_window`

## [0.63.11] - 2023-04-24

Expand Down
5 changes: 4 additions & 1 deletion docs/_docs/01-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ Follow the instructions given below to install Simple Transformers using with An
3. Using a CUDA capable GPU is recommended.
To install Pytorch with CUDA support:
```shell
conda install pytorch>=1.6 cudatoolkit=11.0 -c pytorch
conda install pytorch pytorch-cuda=11.7 -c pytorch -c nvidia
```
CPU only:
```shell
conda install pytorch cpuonly -c pytorch
```

**Note:** Check the [Pytorch website](https://pytorch.org/get-started/locally/) for the latest instructions.
{: .notice--info}

4. Install simpletransformers.
`pip install simpletransformers`

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="simpletransformers",
version="0.63.11",
version="0.64.0",
author="Thilina Rajapakse",
author_email="chaturangarajapakshe@gmail.com",
description="An easy-to-use wrapper library for the Transformers library.",
Expand All @@ -26,7 +26,7 @@
"requests",
"tqdm>=4.47.0",
"regex",
"transformers>=4.6.0",
"transformers>=4.31.0",
"datasets",
"scipy",
"scikit-learn",
Expand Down
19 changes: 13 additions & 6 deletions simpletransformers/classification/classification_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2237,19 +2237,26 @@ def predict(self, to_predict, multi_label=False):
final_preds = []
for pred_row in preds:
mean_pred = np.mean(pred_row)
print(mean_pred)
# print(mean_pred)
final_preds.append(mean_pred)
preds = np.array(final_preds)
else:
preds = [np.argmax(pred, axis=1) for pred in preds]
final_preds = []
for pred_row in preds:
mode_pred, counts = mode(pred_row)
if len(counts) > 1 and counts[0] == counts[1]:
val_freqs_desc = Counter(pred_row).most_common()
if (
len(val_freqs_desc) > 1
and val_freqs_desc[0][1] == val_freqs_desc[1][1]
):
final_preds.append(args.tie_value)
else:
final_preds.append(mode_pred[0])
preds = np.array(final_preds)
final_preds.append(val_freqs_desc[0][0])
# mode_pred, counts = mode(pred_row)
# if len(counts) > 1 and counts[0] == counts[1]:
# final_preds.append(args.tie_value)
# else:
# final_preds.append(mode_pred[0])
preds = np.array(final_preds)
elif not multi_label and args.regression is True:
preds = np.squeeze(preds)
model_outputs = preds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
BertModel,
BertTokenizer,
)
from transformers.models.mmbt.configuration_mmbt import MMBTConfig
from transformers.models.deprecated.mmbt.configuration_mmbt import MMBTConfig

from simpletransformers.classification.classification_utils import (
ImageEncoder,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
import torch.nn as nn
from torch.nn import CrossEntropyLoss, MSELoss
from transformers.models.mmbt.modeling_mmbt import MMBTModel
from transformers.models.deprecated.mmbt.modeling_mmbt import MMBTModel


class MMBTForClassification(nn.Module):
Expand Down
100 changes: 100 additions & 0 deletions train.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!
Hello world with Simple Transformers!

0 comments on commit 12feed2

Please sign in to comment.