Installing tf2.0 in my env but still get ImportError in my code
Author: YangHan-Morningstar
Pull request: no

Hi, I have installed tf2.0 in my env and I followed the readme which says if you have installed the tf2.0 you can just run pip install transformers. But I got Error: "ImportError: cannot import name 'TFBertForSequenceClassification' from 'transformers' (unknown location)"
My code:

from transformers import BertTokenizer, TFBertForSequenceClassification
import tensorflow as tf
tokenizer = BertTokenizer.from_pretrained('bert-base-cased')
model = TFBertForSequenceClassification.from_pretrained('bert-base-cased')
inputs = tokenizer("Hello, my dog is cute", return_tensors="tf")
inputs["labels"] = tf.reshape(tf.constant(1), (-1, 1))  # Batch size 1
outputs = model(inputs)
loss = outputs.loss
logits = outputs.logits

Picture(I have tf2.0 and transformers):
![image](https://user-images.githubusercontent.com/67748964/107148058-172b8c80-698c-11eb-803f-182ea99c23c1.png)

And I also used conda install -c huggingface transformers but it still doesn't work. Could you help me, Thanks!


Comments:
I tried BertForSequenceClassification instead of TFBertForSequenceClassification and it works, I'm confused now

Hi! Version v4.2.2 supports pytorch >=1.3.0 and TensorFlow >=2.3.0. Could you install TensorFlow 2.3.0 and let me know if it fixes your issue?

You can import `BertForSequenceClassification` because that's a PyTorch model and you have your environment correctly setup for torch, but not `TFBertForSequenceClassification` as you have TensorFlow <2.3.0.

After updating tensorflow from 2.0.0 to 2.4.1, it works! Thanks a lot! And I also want to know where can I find version correspondence between huggingface-transformers and tensorflow(or pytorch), for example, if I have tf2.0.0 which version of transformers I should install. Thanks!

This is a good question, and unfortunately we don't have an answer for that except checking the history of the `setup.py`. @jplu can you chime in on what is the last version that was working with the version v2.0.0 of TensorFlow?

The last was v4.1.1

I install the transformers v4.1.1 and my tf is v2.0.0, but when I run the demo, I got an error which says "AttributeError: module 'tensorflow_core.keras.activations' has no attribute 'swish'"

![image](https://user-images.githubusercontent.com/67748964/107304464-0da14200-6abc-11eb-8eb2-6f4199a6dca4.png)

First I went to view the official documentation transformers v4.1.1 but got 404

![image](https://user-images.githubusercontent.com/67748964/107304583-51944700-6abc-11eb-9302-653e6ebb8b07.png)


Hello, could you try loading the doc again? It should be back up. Thanks!

Ah yes, the `swish` activation needs at least TF 2.1. Then you should be able to run 2.0 with at least Transformers v3.1.0

> Hello, could you try loading the doc again? It should be back up. Thanks!

I tried in my iPhone and it could be loaded but when I tried it in my mac, it failed...

> Ah yes, the `swish` activation needs at least TF 2.1. Then you should be able to run 2.0 with at least Transformers v3.1.0

TF2.0 and Transformers3.1.0 and there are another Error happend: "ImportError: cannot import name 'Parallel' from 'joblib' (unknown location)"

I think you have to downgrade your version of joblib as well.

Now I can import it correctly but still got an error that "OSError: Unable to load weights from h5 file. If you tried to load a TF 2.0 model from a PyTorch checkpoint, please set from_pt=True."

I downloaded the file "bert-base-uncased" from the official website but there is only tf_model.h5 instead of tf_model.hdf5.

My code:

from transformers import BertTokenizer, TFBertForSequenceClassification
import tensorflow as tf

pretrain_path = "/root/huggingface-pretrain/bert-base-uncased"
tokenizer = BertTokenizer.from_pretrained(pretrain_path)
model = TFBertForSequenceClassification.from_pretrained(pretrain_path)
inputs = tokenizer("Hello, my dog is cute", return_tensors="tf")
inputs["labels"] = tf.reshape(tf.constant(1), (-1, 1))  # Batch size 1
outputs = model(inputs)
loss = outputs.loss
logits = outputs.logits

Did you try with `TFBertForSequenceClassification.from_pretrained("bert-base-uncased")` instead? What is the content of your `/root/huggingface-pretrain/bert-base-uncased` folder?

I have tried but it didn't work

I suggest that you can open multiple version including the Code and Model Format so that everyone can use them just using their TensorFlow version.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.