is there a method to transform array to tensor tensorflow?

i want to train text to determine if text positive , neutral or negative , so i trained the BERT base model but at the end at the step of learner.validate it return an error, can you help me please ?

 !pip install ktrain==0.23.2
 import ktrain

 X=["hello","i'am here..","..."]
 y=np.array([1,2,0,2,1,2,0,1,1,...])
 categories=["neg","neut","pos"]
 X_train, X_test, y_train, y_test = train_test_split(X[:100], y[:100], test_size=0.33, 
 random_state=42)
 model_name='distilbert-base-multilingual-cased'
 trans = text.Transformer(model_name, maxlen=512, class_names=categories)
 train_data=trans.preprocess_train(X_train,y_train)
 test_data = trans.preprocess_test(X_test, y_test)
 model= trans.get_classifier()
 learner= ktrain.get_learner(model, train_data=train_data,val_data=test_data,batch_size=8)
 learner.fit_onecycle(3e-5,1)
 learner.validate(class_names=categories)

but i get error :

      ValueError                                Traceback (most recent call last)
     <ipython-input-39-d99399b4f681> in <module>()
     ----> 1 learner.validate(class_names=categories)

     8 frames
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/constant_op.py in 
   convert_to_eager_tensor(value, ctx, dtype)
   96       dtype = dtypes.as_dtype(dtype).as_datatype_enum
   97   ctx.ensure_initialized()
   ---> 98   return ops.EagerTensor(value, ctx.device_name, dtype)
   99 
   100 

   ValueError: Attempt to convert a value (TFSequenceClassifierOutput(loss=None, 
   logits=array([[-0.14492714, -0.308572  ,  0.41551754],
   [-0.02239409, -0.22379267,  0.13737921],
   [-0.15169457, -0.26776308,  0.3646287 ],
   [-0.11638386, -0.30610234,  0.42503807],
   [-0.14799587, -0.2751274 ,  0.3999261 ],
   [-0.1224369 , -0.2705566 ,  0.37462863],
   [-0.16992202, -0.26875758,  0.38301754],
   [-0.02906444, -0.22582646,  0.16817996],
   [-0.14451084, -0.3335299 ,  0.45228514],
   [-0.12560453, -0.15705517,  0.3202087 ],
   [-0.1477989 , -0.28774017,  0.40492412],
   [-0.15207294, -0.27476442,  0.41782793],
   [-0.14203653, -0.24748898,  0.4224902 ],
   [-0.02594737, -0.23538935,  0.17150217],
   [-0.10563572, -0.31230217,  0.37387425],
   [-0.13637367, -0.28157175,  0.38459644],
   [-0.14043958, -0.29381162,  0.41240314],
   [-0.03989747, -0.23261254,  0.19984315],
   [-0.12188954, -0.25612894,  0.4106647 ],
   [-0.1576367 , -0.32221746,  0.44524238],
   [-0.14458796, -0.29356796,  0.43222305],
   [-0.0947336 , -0.26198757,  0.30835733],
   [-0.18257669, -0.28770167,  0.43495163],
   [-0.17199922, -0.27865767,  0.3720437 ],
   [-0.12301907, -0.2829709 ,  0.42322537],
   [-0.10598033, -0.2630937 ,  0.36105153],
   [-0.01495049, -0.21938747,  0.14062764],
   [-0.12164614, -0.3101943 ,  0.4182844 ],
   [-0.10304911, -0.24770047,  0.353735  ],
   [-0.16426452, -0.29451552,  0.42003003],
   [-0.16851503, -0.2555803 ,  0.41026738],
   [-0.10907209, -0.26942176,  0.40432337],
   [-0.13107793, -0.25909895,  0.34871536]], dtype=float32), hidden_states=None, attentions=None)) 
    with an unsupported type (<class 'transformers.modeling_tf_outputs.TFSequenceClassifierOutput'>) 
    to a Tensor.

how we can fix this problem, i find on the internet is that this problem is related to the version of tensorflow but i tried the version of tensorflow 2.1 but i have the same problem…. any ideas please

Source: Python-3x Questions

LEAVE A COMMENT