File size: 7,527 Bytes
89f8ecc
 
282c553
89f8ecc
 
282c553
 
 
89f8ecc
 
 
282c553
 
 
 
 
 
 
 
 
 
89f8ecc
 
282c553
89f8ecc
282c553
89f8ecc
282c553
89f8ecc
282c553
89f8ecc
282c553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89f8ecc
 
 
 
 
282c553
 
 
 
 
89f8ecc
 
282c553
 
 
 
 
 
 
 
 
89f8ecc
 
282c553
 
 
 
 
 
 
 
 
 
 
 
89f8ecc
282c553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89f8ecc
 
282c553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89f8ecc
282c553
89f8ecc
282c553
89f8ecc
282c553
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
---
license: apache-2.0
language: en
tags:
- text-classification
- financial-text
- boilerplate-detection
- analyst-reports
- transformers
pipeline_tag: text-classification
widget:
- text: "EEA - The securities and related financial instruments described herein may not be eligible for sale in all jurisdictions or to certain categories of investors."
  example_title: "Legal Disclaimer"
- text: "This report contains forward-looking statements that involve risks and uncertainties regarding future events."
  example_title: "Forward-Looking Statement"
- text: "Our revenue increased by 15% compared to last quarter due to strong demand in emerging markets."
  example_title: "Business Performance"
- text: "The information contained herein is confidential and proprietary and may not be disclosed without written permission."
  example_title: "Confidentiality Notice"
- text: "We launched three innovative products this quarter that exceeded our initial sales projections by 40%."
  example_title: "Product Update"
---

# Boilerplate Detection Model for Financial Documents

This model detects boilerplate (formulaic/repetitive) text in financial analyst reports, distinguishing it from substantive business content.

## Model Description

Developed for analyzing corporate culture discussions in analyst reports by filtering out standardized boilerplate content including legal disclaimers, forward-looking statements, and other formulaic language.

### Research Context

This model was developed as part of the research paper "Dissecting Corporate Culture Using Generative AI" to preprocess analyst reports for culture analysis. The model identifies and removes boilerplate segments that would otherwise introduce noise in substantive content analysis.

### Training Methodology

1. **Data Collection**: 
   - 2.4 million analyst reports from Thomson One's Investext (2000-2020)
   - Reports from top 20 brokers by volume analyzed systematically

2. **Training Data**:
   - **Positive examples (boilerplate)**: Top 10% most frequently repeated segments per broker-year, appearing ≥5 times
   - **Negative examples**: Randomly selected non-repeated segments
   - **Dataset**: 547,790 examples (54,779 boilerplate, 493,011 non-boilerplate)
   - **Split**: 80/10/10 for train/validation/test

3. **Architecture Design**:
   - **Embedding Layer**: Frozen sentence-transformers/all-mpnet-base-v2
   - **Pooling**: Mean pooling over token embeddings
   - **Classification Head**: Lightweight 3-layer MLP (768 → 16 → 8 → 2)
   - **Strategy**: Frozen embeddings preserve semantic understanding while classification head learns boilerplate patterns

4. **Performance Metrics**:
   - **Test AUC**: 0.966
   - **False Positive Rate**: 0.093
   - **False Negative Rate**: 0.073
   - **Decision threshold**: 0.22 (median probability)

## Intended Uses

### Primary Use Cases
- Preprocessing financial analyst reports for content analysis
- Filtering boilerplate from earnings call transcripts
- Cleaning regulatory filings for substantive information extraction
- Preparing financial text for sentiment analysis or topic modeling

### Out-of-Scope Uses
- General web content filtering (trained on financial documents)
- Non-English text classification
- Real-time streaming applications (optimized for batch processing)

## Usage Examples

### Using the Transformers Pipeline (Recommended)

```python
from transformers import pipeline

# Load the model (requires trust_remote_code=True for custom architecture)
classifier = pipeline(
    "text-classification",
    model="maifeng/boilerplate_detection",
    trust_remote_code=True,
    device=0 if torch.cuda.is_available() else -1
)

# Single text classification
text = "This report contains forward-looking statements that involve risks and uncertainties."
result = classifier(text)
print(result)
# Output: [{'label': 'BOILERPLATE', 'score': 0.9987}]

# Batch classification for efficiency
texts = [
    "Revenue increased by 15% this quarter driven by strong product demand.",
    "The securities described herein may not be eligible for sale in all jurisdictions.",
    "Our new AI initiative has reduced operational costs by 30%.",
    "Past performance is not indicative of future results.",
]

results = classifier(texts, batch_size=32)
for text, result in zip(texts, results):
    label = result['label']
    score = result['score']
    print(f"{'[BOILERPLATE]' if label == 'BOILERPLATE' else '[CONTENT]    '} "
          f"(confidence: {score:.1%}) {text[:60]}...")
```

### Direct Model Usage

```python
from transformers import AutoTokenizer, AutoModel
import torch

# Load model and tokenizer with trust_remote_code
model = AutoModel.from_pretrained(
    "maifeng/boilerplate_detection",
    trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained("maifeng/boilerplate_detection")

# Prepare input
texts = ["Your text here", "Another example"]
inputs = tokenizer(
    texts,
    padding=True,
    truncation=True,
    max_length=512,
    return_tensors="pt"
)

# Get predictions
model.eval()
with torch.no_grad():
    outputs = model(**inputs)
    probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
    
# Process results
for i, text in enumerate(texts):
    probs = probabilities[i].numpy()
    label = "BOILERPLATE" if probs[1] > 0.5 else "NOT_BOILERPLATE"
    confidence = probs[1] if label == "BOILERPLATE" else probs[0]
    print(f"{label}: {confidence:.2%} - {text[:50]}...")
```

### Integration in Document Processing Pipeline

```python
def filter_boilerplate(documents, threshold=0.5):
    """Filter out boilerplate segments from documents"""
    classifier = pipeline(
        "text-classification",
        model="maifeng/boilerplate_detection",
        trust_remote_code=True
    )
    
    results = classifier(documents, batch_size=32)
    
    filtered_docs = []
    for doc, result in zip(documents, results):
        if result['label'] == 'NOT_BOILERPLATE' or result['score'] < threshold:
            filtered_docs.append(doc)
    
    return filtered_docs

# Example usage
analyst_reports = [...]  # Your document segments
substantive_content = filter_boilerplate(analyst_reports)
print(f"Retained {len(substantive_content)}/{len(analyst_reports)} segments")
```

## Model Limitations

1. **Domain Specificity**: Optimized for financial analyst reports; performance may degrade on other document types
2. **Temporal Bias**: Trained on 2000-2020 data; newer boilerplate patterns may not be recognized
3. **Language**: English-only model
4. **Context Window**: Maximum 512 tokens per segment
5. **Binary Classification**: Does not distinguish between types of boilerplate

## Ethical Considerations

- **Transparency**: Users should understand that substantive content may occasionally be misclassified as boilerplate
- **Bias**: Training data from top brokers may not represent all financial communication styles
- **Use Case**: Should not be used as sole method for regulatory compliance or legal document analysis

## Citation

```bibtex
@article{mai2024dissecting,
  title={Dissecting Corporate Culture Using Generative AI},
  author={Mai, Feng and others},
  journal={Working Paper},
  year={2024}
}
```

## Technical Requirements

- Python 3.7+
- PyTorch 1.9+
- Transformers 4.20+
- CUDA (optional, for GPU acceleration)

## License

Apache 2.0 - See LICENSE file for details

## Contact

For questions or issues, please open an issue on the [model repository](https://huggingface.co/maifeng/boilerplate_detection).