One (or more) of the element strings supplied to literal_eval cannot be parsed by literal_eval.. That is, the program syntax is valid (or else the program would fail without running anything!), and it is one or more of the element values supplied to literal_eval is not valid Python!
The first step is to identify some 'invalid' values, eg.
from ast import literal_eval
import re
train_data_list = []
for i in range(len(train_data)):
a = re.search(train_data.subtext[i], train_data.text[i])
if a is not None:
element = '("' +train_data.text[i] + '"' + ', {"entities": [(' + str(a.start()) + ',' + str(a.end()) + ',"SKILL")]})'
try:
data = literal_eval(element)
train_data_list.append(data)
except:
print("Failed to parse element as a Python literal!")
print(">>")
print(repr(element))
print("<<")
If the above "runs" (fsvo. "runs") then the proposed hypothesis holds the non-relevant answers can be ignored ;-)
Anyway, the solution is to not use literal_eval at all. Instead, create an object directly:
for i in range(len(train_data)):
a = re.search(train_data.subtext[i], train_data.text[i])
if a is not None:
# might be a bit off.. YMMV.
data = (train_data.text[i],
{"entities": [(str(a.start()), str(a.end()), "SKILL")]})
train_data_list.append(data)
Now, if values of train_data.text[i] contain a \n - that is, the literal two-character '\' and 'n' escape sequence - there may be additional work required to turn those into newline characters .. but one step at a time. And no step should be backward! :D
elementas the time ofliteral_eval. Fix the code to ensue it is valid: I suspect it might be .. 'funky'.literal_eval. If a specific example is identified the problem should be 'clear'. Include the specific value ofelementin such failing cases in the question, so that proper solutions can be suggested.\ncreate asset tracking database used for gain/loss profits, facility overhead, and finance research, including\nassisting in the implementation of sap business one. email correspondence, and proposal correspondence (both the\ncreation and assessment of). contract negotiations from customer/client to third party vendors and facilities.\nbuilt solid, transparent client /vendor relationships, with high client/vendor retention.Even in the case where the text has"It worked fine.element, which would be something like("...", {"entities": [(...,"SKILL")]})were the ...'s are "some data". (I was wrong on the"bit - that would be a different error if manifested ^_^.)