Path: blob/master/47_BERT_text_classification/BERT_email_classification-Copy1.ipynb
1141 views
Kernel: Python 3
In [1]:
In [2]:
Out[2]:
In [3]:
Out[3]:
In [4]:
Out[4]:
In [5]:
In [21]:
In [22]:
Out[22]:
<tf.Tensor: shape=(2, 768), dtype=float32, numpy=
array([[-0.8435169 , -0.51327276, -0.8884574 , ..., -0.74748874,
-0.75314736, 0.91964483],
[-0.87208366, -0.50543964, -0.94446677, ..., -0.858475 ,
-0.7174535 , 0.8808298 ]], dtype=float32)>
In [15]:
Out[15]:
In [18]:
Out[18]:
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-18-0ac2523913ee> in <module>
----> 1 encoding_column = df['Message'].map(get_sentence_encoding)
2 encoding_column
C:\Program Files\Python38\lib\site-packages\pandas\core\series.py in map(self, arg, na_action)
3826 dtype: object
3827 """
-> 3828 new_values = super()._map_values(arg, na_action=na_action)
3829 return self._constructor(new_values, index=self.index).__finalize__(self)
3830
C:\Program Files\Python38\lib\site-packages\pandas\core\base.py in _map_values(self, mapper, na_action)
1298
1299 # mapper is a function
-> 1300 new_values = map_f(values, mapper)
1301
1302 return new_values
pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()
<ipython-input-6-b2b66895fa35> in get_sentence_encoding(sentence)
1 def get_sentence_encoding(sentence):
----> 2 preprocessed_result = bert_preprocess([sentence])
3 return bert_encoder(preprocessed_result)['pooled_output'][0].numpy()
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self, *args, **kwargs)
1028 with autocast_variable.enable_auto_cast_variables(
1029 self._compute_dtype_object):
-> 1030 outputs = call_fn(inputs, *args, **kwargs)
1031
1032 if self._activity_regularizer:
C:\Program Files\Python38\lib\site-packages\tensorflow_hub\keras_layer.py in call(self, inputs, training)
233 else:
234 training = False
--> 235 result = smart_cond.smart_cond(training,
236 lambda: f(training=True),
237 lambda: f(training=False))
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\framework\smart_cond.py in smart_cond(pred, true_fn, false_fn, name)
54 return true_fn()
55 else:
---> 56 return false_fn()
57 else:
58 return control_flow_ops.cond(pred, true_fn=true_fn, false_fn=false_fn,
C:\Program Files\Python38\lib\site-packages\tensorflow_hub\keras_layer.py in <lambda>()
235 result = smart_cond.smart_cond(training,
236 lambda: f(training=True),
--> 237 lambda: f(training=False))
238
239 # Unwrap dicts returned by signatures.
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\saved_model\load.py in _call_attribute(instance, *args, **kwargs)
668
669 def _call_attribute(instance, *args, **kwargs):
--> 670 return instance.__call__(*args, **kwargs)
671
672
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\eager\def_function.py in __call__(self, *args, **kwds)
887
888 with OptionalXlaContext(self._jit_compile):
--> 889 result = self._call(*args, **kwds)
890
891 new_tracing_count = self.experimental_get_tracing_count()
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\eager\def_function.py in _call(self, *args, **kwds)
922 # In this case we have not created variables on the first call. So we can
923 # run the first trace but we should fail if variables are created.
--> 924 results = self._stateful_fn(*args, **kwds)
925 if self._created_variables:
926 raise ValueError("Creating variables on a non-first call to a function"
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\eager\function.py in __call__(self, *args, **kwargs)
3021 (graph_function,
3022 filtered_flat_args) = self._maybe_define_function(args, kwargs)
-> 3023 return graph_function._call_flat(
3024 filtered_flat_args, captured_inputs=graph_function.captured_inputs) # pylint: disable=protected-access
3025
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\eager\function.py in _call_flat(self, args, captured_inputs, cancellation_manager)
1958 and executing_eagerly):
1959 # No tape is watching; skip to running the function.
-> 1960 return self._build_call_outputs(self._inference_function.call(
1961 ctx, args, cancellation_manager=cancellation_manager))
1962 forward_backward = self._select_forward_and_backward_functions(
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\eager\function.py in call(self, ctx, args, cancellation_manager)
589 with _InterpolateFunctionError(self):
590 if cancellation_manager is None:
--> 591 outputs = execute.execute(
592 str(self.signature.name),
593 num_outputs=self._num_outputs,
~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\eager\execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
57 try:
58 ctx.ensure_initialized()
---> 59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
60 inputs, attrs, num_outputs)
61 except core._NotOkStatusException as e:
KeyboardInterrupt:
In [17]:
Out[17]:
<ipython-input-17-68e77860ae13>:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
df_n['e'] = encoding_column
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: