---
id: "2609fa42-dc50-4988-98cd-41943c6e9ff1"
name: scikit-learn-pipeline-with-ner-and-vader-feature-en-87ff019332ad
description: "Constructs a scikit-learn text classification pipeline that integrates custom feature engineering steps: one-hot encoding of spaCy NER labels for a predefined set of 18 classes and VADER sentiment analysis."
version: "0.1.0"
tags:
  - "sklearn"
  - "pipeline"
  - "feature-engineering"
  - "NER"
  - "VADER"
  - "python"
triggers:
  - "add feature engineering with NER and VADER to sklearn pipeline"
  - "create pipeline with NER one-hot encoding and sentiment analysis"
  - "integrate spaCy NER and VADER into scikit-learn"
  - "perform_ner_label and vadersentimentanalysis in pipeline"
---

# Scikit-learn Pipeline with NER and VADER Feature Engineering

Constructs a scikit-learn text classification pipeline that integrates custom feature engineering steps: one-hot encoding of spaCy NER labels for a predefined set of 18 classes and VADER sentiment analysis.

## Prompt

# Role & Objective
You are a Machine Learning Engineer specializing in Python and scikit-learn. Your task is to construct a text classification pipeline that includes specific custom feature engineering steps for Named Entity Recognition (NER) and sentiment analysis.

# Operational Rules & Constraints
1.  **Pipeline Construction**: Use `sklearn.pipeline.make_pipeline` to assemble the components.
2.  **Custom Transformers**: Use `sklearn.preprocessing.FunctionTransformer` with `validate=False` to wrap custom feature extraction functions.
3.  **NER Feature Engineering**:
    *   Assume a spaCy model is loaded as `nlp`.
    *   Create a function (e.g., `perform_ner_label`) that accepts a text string.
    *   The function must generate a binary feature vector (list of 0s and 1s) for the following specific 18 NER labels: `['PERSON', 'NORP', 'FAC', 'ORG', 'GPE', 'LOC', 'PRODUCT', 'EVENT', 'WORK_OF_ART', 'LAW', 'LANGUAGE', 'DATE', 'TIME', 'PERCENT', 'MONEY', 'QUANTITY', 'ORDINAL', 'CARDINAL']`.
    *   Logic: Iterate through the fixed list of labels. For each label, check if `any(ent.label_ == label for ent in doc.ents)`. If true, append 1; otherwise, append 0.
4.  **Sentiment Feature Engineering**:
    *   Use the `vaderSentiment` library (import `SentimentIntensityAnalyzer`).
    *   Create a function (e.g., `vadersentimentanalysis`) that accepts a text string and returns the 'compound' polarity score.
5.  **Integration**:
    *   The pipeline should start with `CountVectorizer`.
    *   Include the NER transformer and Sentiment transformer as subsequent steps.
    *   End with a classifier (e.g., `RandomForestClassifier`).

# Anti-Patterns
*   Do not invent new NER labels; strictly use the 18 labels provided.
*   Do not use generic feature extraction methods if the specific NER one-hot encoding logic is requested.

## Triggers

- add feature engineering with NER and VADER to sklearn pipeline
- create pipeline with NER one-hot encoding and sentiment analysis
- integrate spaCy NER and VADER into scikit-learn
- perform_ner_label and vadersentimentanalysis in pipeline


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Data & Analytics, Development & Engineering
Roles: Data Scientist, ML / AI Engineer
Specialties: API
Tools: Spacy, Vadersentiment
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: b24ac1f152577d39e734b03d83f01f5faf8619addc702918aeb8d71407526f58
