Spaces:
Running
Running
mohsenfayyaz
commited on
Commit
•
58760f7
1
Parent(s):
e3bee57
Upload 5 files
Browse files- DecompX/README.md +1 -0
- DecompX/requirements.txt +11 -0
- DecompX/src/globenc_utils.py +49 -0
- DecompX/src/modeling_bert.py +0 -0
- DecompX/src/modeling_roberta.py +0 -0
DecompX/README.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
# DecompX
|
DecompX/requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
scikit-learn
|
2 |
+
scipy
|
3 |
+
pandas
|
4 |
+
regex
|
5 |
+
numpy
|
6 |
+
notebook
|
7 |
+
jupyter
|
8 |
+
ipykernel
|
9 |
+
ipython
|
10 |
+
datasets==1.18.3
|
11 |
+
transformers==4.17.0
|
DecompX/src/globenc_utils.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from dataclasses import dataclass
|
3 |
+
from typing import List, Optional, Tuple, Union
|
4 |
+
|
5 |
+
@dataclass
|
6 |
+
class GlobencConfig():
|
7 |
+
include_biases: Optional[bool] = True
|
8 |
+
bias_decomp_type: Optional[str] = "absdot" # "absdot": Based on the absolute value of dot products | "norm": Based on the norm of the attribution vectors | "equal": equal decomposition | "abssim": Based on the absolute value of cosine similarites | "cls": add to cls token
|
9 |
+
include_bias_token: Optional[bool] = False # Adds an extra input token as a bias in the attribution vectors
|
10 |
+
# If the bias_decomp_type is None and include_bias_token is True then the final token in the input tokens of the attr. vectors will be the summation of the biases
|
11 |
+
# Otherwise the bias token will be decomposed with the specified decomp type
|
12 |
+
|
13 |
+
include_LN1: Optional[bool] = True
|
14 |
+
|
15 |
+
include_FFN: Optional[bool] = True
|
16 |
+
FFN_approx_type: Optional[str] = "GeLU_ZO" # "GeLU_LA": GeLU-based linear approximation | "ReLU": Using ReLU as an approximation | "GeLU_ZO": Zero-origin slope approximation
|
17 |
+
FFN_fast_mode: Optional[bool] = False
|
18 |
+
|
19 |
+
include_LN2: Optional[bool] = True
|
20 |
+
|
21 |
+
aggregation: Optional[str] = None # None: No aggregation | vector: Vector-based aggregation | rollout: Norm-based rollout aggregation
|
22 |
+
|
23 |
+
include_classifier_w_pooler: Optional[bool] = True
|
24 |
+
tanh_approx_type: Optional[str] = "ZO" # "ZO": Zero-origin slope approximation | "LA": Linear approximation
|
25 |
+
|
26 |
+
output_all_layers: Optional[bool] = False # True: Output all layers | False: Output only last layer
|
27 |
+
output_attention: Optional[str] = None # None | norm | vector | both
|
28 |
+
output_res1: Optional[str] = None # None | norm | vector | both
|
29 |
+
output_LN1: Optional[str] = None # None | norm | vector | both
|
30 |
+
output_FFN: Optional[str] = None # None | norm | vector | both
|
31 |
+
output_res2: Optional[str] = None # None | norm | vector | both
|
32 |
+
output_encoder: Optional[str] = None # None | norm | vector | both
|
33 |
+
output_aggregated: Optional[str] = None # None | norm | vector | both
|
34 |
+
output_pooler: Optional[str] = None # None | norm | vector | both
|
35 |
+
|
36 |
+
output_classifier: Optional[bool] = True
|
37 |
+
|
38 |
+
|
39 |
+
@dataclass
|
40 |
+
class GlobencOutput():
|
41 |
+
attention: Optional[Union[Tuple[torch.Tensor, Tuple[torch.Tensor]], Tuple[torch.Tensor], torch.Tensor]] = None
|
42 |
+
res1: Optional[Union[Tuple[torch.Tensor, Tuple[torch.Tensor]], Tuple[torch.Tensor], torch.Tensor]] = None
|
43 |
+
LN1: Optional[Union[Tuple[torch.Tensor, Tuple[torch.Tensor]], Tuple[torch.Tensor], torch.Tensor]] = None
|
44 |
+
FFN: Optional[Union[Tuple[torch.Tensor, Tuple[torch.Tensor]], Tuple[torch.Tensor], torch.Tensor]] = None
|
45 |
+
res2: Optional[Union[Tuple[torch.Tensor, Tuple[torch.Tensor]], Tuple[torch.Tensor], torch.Tensor]] = None
|
46 |
+
encoder: Optional[Union[Tuple[torch.Tensor, Tuple[torch.Tensor]], Tuple[torch.Tensor], torch.Tensor]] = None
|
47 |
+
aggregated: Optional[Union[Tuple[torch.Tensor, Tuple[torch.Tensor]], Tuple[torch.Tensor], torch.Tensor]] = None
|
48 |
+
pooler: Optional[Union[Tuple[torch.Tensor], torch.Tensor]] = None
|
49 |
+
classifier: Optional[torch.Tensor] = None
|
DecompX/src/modeling_bert.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|
DecompX/src/modeling_roberta.py
ADDED
The diff for this file is too large to render.
See raw diff
|
|