|
|
|
|
|
""" |
|
|
Example usage of screenplay salience features from Hugging Face. |
|
|
""" |
|
|
|
|
|
from datasets import load_dataset |
|
|
import pandas as pd |
|
|
from sklearn.linear_model import LogisticRegression |
|
|
from sklearn.metrics import classification_report |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Loading training data...") |
|
|
ds = load_dataset( |
|
|
"YOUR_USERNAME/screenplay-features", |
|
|
data_files={ |
|
|
"train": ["train/base.parquet", "train/gc_polarity.parquet"], |
|
|
"test": ["test/base.parquet", "test/gc_polarity.parquet"] |
|
|
} |
|
|
) |
|
|
|
|
|
train_df = ds['train'].to_pandas() |
|
|
test_df = ds['test'].to_pandas() |
|
|
|
|
|
|
|
|
feature_cols = [c for c in train_df.columns if c not in ["movie_id", "scene_index", "label"]] |
|
|
|
|
|
X_train = train_df[feature_cols] |
|
|
y_train = train_df["label"] |
|
|
|
|
|
X_test = test_df[feature_cols] |
|
|
y_test = test_df["label"] |
|
|
|
|
|
print(f"Train: {len(X_train)} samples, {len(feature_cols)} features") |
|
|
print(f"Test: {len(X_test)} samples") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("\nTraining logistic regression...") |
|
|
clf = LogisticRegression(max_iter=1000, random_state=42) |
|
|
clf.fit(X_train.fillna(0), y_train) |
|
|
|
|
|
|
|
|
y_pred = clf.predict(X_test.fillna(0)) |
|
|
print("\nTest Results:") |
|
|
print(classification_report(y_test, y_pred, target_names=["Non-salient", "Salient"])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("\nTop 10 features by coefficient:") |
|
|
feature_importance = pd.DataFrame({ |
|
|
'feature': feature_cols, |
|
|
'coefficient': clf.coef_[0] |
|
|
}).sort_values('coefficient', key=abs, ascending=False) |
|
|
|
|
|
print(feature_importance.head(10)) |
|
|
|