File size: 2,454 Bytes
7804693
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import csv, re, warnings
import numpy as np, pandas as pd
from sklearn.linear_model import RidgeCV
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.impute import SimpleImputer
from sklearn.ensemble import ExtraTreesRegressor
from sklearn.model_selection import GroupKFold, cross_val_predict
from text_features import interviewee_turns, text_features
warnings.filterwarnings("ignore")

feat = pd.read_csv("evalbot_features.csv").set_index("interview")
tx = {}
for row in csv.reader(open("interview_transcripts_by_turkers.csv", encoding="utf-8", errors="replace")):
    if len(row) >= 2:
        tx[row[0].strip().lower()] = text_features(interviewee_turns(row[1]))
feat = feat.join(pd.DataFrame(tx).T)
s = pd.read_csv("turker_scores_full_interview.csv")
y = s[s.Worker == "AGGR"].assign(Participant=lambda d: d.Participant.str.lower()).set_index("Participant")
traits = ["Overall", "RecommendHiring", "Excited", "EngagingTone", "Friendly", "Smiled", "EyeContact", "NoFillers",
          "StructuredAnswers", "Calm", "NotAwkward", "Engaged", "Focused"]
data = feat.join(y[traits], how="inner")
groups = data.index.str.extract(r"(\d+)")[0].astype(int).values
sets = {
    "prosody": [c for c in feat.columns if c.startswith("pros_")],
    "face": [c for c in feat.columns if c.startswith("face_")],
    "smile": [c for c in feat.columns if c.startswith("smile_")],
    "text": [c for c in feat.columns if c.startswith("txt_")],
}
sets["all"] = sum(sets.values(), [])
cv = GroupKFold(n_splits=10)

def model(kind):
    if kind == "ridge":
        return make_pipeline(SimpleImputer(), StandardScaler(), RidgeCV(alphas=np.logspace(-1, 4, 30)))
    return make_pipeline(SimpleImputer(), ExtraTreesRegressor(n_estimators=400, min_samples_leaf=3, max_features=0.3, random_state=0, n_jobs=-1))

res = {}
for name, cols in sets.items():
    X = data[cols].replace([np.inf, -np.inf], np.nan).values
    for t in traits:
        best = -1
        for kind in ("ridge", "trees"):
            pred = cross_val_predict(model(kind), X, data[t].values, cv=cv, groups=groups)
            r = np.corrcoef(pred, data[t].values)[0, 1]
            res[(t, name, kind)] = r
print("n =", len(data))
tab = pd.Series(res).unstack([1, 2]).round(2)
best = tab.T.groupby(level=0).max().T
print(best[["prosody", "face", "smile", "text", "all"]].to_string())
tab.to_csv("benchmark_results.csv")
data.to_csv("training_table.csv")