0
$\begingroup$

I have a csv with different questions, answer and question types. So far I have only been able to differentiate the questions between muliple answers and likert scale. I would rather like to get the type of questions (when question, where questions, ...) as well as the intentions behind the question (eating, sleepling ...). Here is the csv:

    QID Questions   Answers QType
0   H1  When do you think your next vacation can start? ['In next 3 months', 'In next 6 months', 'In next 1 year', 'Only once COVID-19 is under control', 'Only once COVID-19 vaccine is developed']    Multiple Choice
1   H2  What are your preferences regarding medical treatment policy (with additional cost)?    ["Doctor's availability in hotel", 'Ventilator availability in hotel', 'Tie-ups with nearby hospitals', 'Availability of medical rooms with primary first aid care']    Multiple Choice
2   H3  What is your preferences of complementary breakfast?    ['Buffet breakfast with social distancing', 'Buffet breakfast replaced with Ala-carte with limited options', 'Breakfast to be delivered in room with limited options (chargeable)', 'Packaged breakfast only']  Multiple Choice
3   H4  What is your preference for a in-hotel grocery shops for the basic necessity items and packaged food?   ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] Likert Scale
4   H5  Consumer Personality    ['']    Multiple Choice
5   H6  What is your preference of hotel check-in?  ['Collect keys at the counter maintaining social distancing', 'Collect keys at the KIOSK using booking bar-code', 'Online Keys using the mobile App']   Multiple Choice
6   H7  What is your preference of payment during Check-out?    ['Pay at the counter maintaining social distancing', 'Pay at KIOSK', 'Online payment using the mobile App'] Multiple Choice
7   H8  What is your preference of hotel cancellation / travel date change policy?  ['Travel date change is preferred at no cost', 'Cancellation at some minimal cost (based on hotel policy)', 'Cancellation with some amount refund and hotel coupons for next visit']    Multiple Choice
8   H9  What is your preference of the guest policy?    ['Guests are allowed in living room with precautions', 'Guest are allowed only in certain designated areas', 'No guests are allowed inside hotel']  Multiple Choice
9   H10 What is your preference of the concierge service?   ['Regular concierge services', 'Online concierge service']  Multiple Choice
10  H11 Consumer Intentions ['']    Multiple Choice

So the categories can be the wh questions, the intents can be ... anything related to the intentions but one can notice that some lines have no answers (['']), these are just section titles of the whole questionnaire and should be detected as such.

My code:

def classifier(l):
...     l = ast.literal_eval(f"{l}")
...     try:
...         l = list(map(int, l))
...     except ValueError:
...         pass
...     if not l:
...         return None
...     try: 
...         if all(isinstance(x, int) for x in l):
...             return "Likert Scale"
...         else:
...             return "Multiple Choice"
...     except:
...         return None
... 
... df.QType = df.apply(lambda row: classifier(row['Answers']), axis = 1)
df.QType
0       Multiple Choice
1       Multiple Choice
2       Multiple Choice
3          Likert Scale
4       Multiple Choice
             ...       

Update:

I've tried to get the intents and differentiate with sextions using deep pavlov:

!pip install fasttext

from deeppavlov import build_model, configs

CONFIG_PATH = configs.classifiers.intents_snips  # could also be configuration dictionary or string path or `pathlib.Path` instance

model = build_model(CONFIG_PATH, download=True)  # in case of necessity to download some data

model = build_model(CONFIG_PATH, download=False)  # otherwise

print(model(["What is the weather in Boston today?"]))

from google.colab import auth
auth.authenticate_user()
import gspread 
from oauth2client.client import GoogleCredentials
gc = gspread.authorize(GoogleCredentials.get_application_default())
wb = gc.open_by_url('https://docs.google.com/spreadsheets/d/1g...')
sheet = wb.worksheet('qa_cleaned_6')
data = sheet.get_all_values()
df = pd.DataFrame(data)

for question in df.Questions.head().iteritems():
  question= question[1]
  print("question: ",question , "type: ", model([question]))

But got:

question:  When do you think your next vacation can start? type:  ['PlayMusic']
question:  What are your preferences regarding medical treatment policy (with additional cost)? type:  ['SearchScreeningEvent']
question:  What is your preferences of complementary breakfast? type:  ['SearchScreeningEvent']
question:  What is your preference for a in-hotel grocery shops for the basic necessity items and packaged food? type:  ['BookRestaurant']
question:  Consumer Personality type:  ['PlayMusic']
$\endgroup$
  • $\begingroup$ Can you explicitly describe what categories you want to classify questions into ? One approach would be to check if words in a question or its choices fall into a given vocabulary. For example if the choices contain "month", "year" etc. Then it would be "time" question... $\endgroup$ – Adam Oudad Jun 29 at 15:45
  • $\begingroup$ @AdamOudad Yes I already tried that approach to differentiate between Likert and the others. The set of categories I'm looking for is open-ended so it can be open to new types of questions $\endgroup$ – Revolucion for Monica Jun 29 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.