Views
No views yet
1from transformers import pipeline
2import numpy as np
3
4# Init text classification pipeline
5text_cls_pipe = pipeline(task="text-classification",
6 model="coastalcph/danish-legal-longformer-eurlex-sd",
7 use_auth_token='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')
8
9# Encode and Classify document
10predictions = text_cls_pipe("KOMMISSIONENS BESLUTNING\naf 6. marts 2006\nom klassificering af visse byggevarers "
11 "ydeevne med hensyn til reaktion ved brand for så vidt angår trægulve samt vægpaneler "
12 "og vægbeklædning i massivt træ\n(meddelt under nummer K(2006) 655")
13
14# Print prediction
15print(predictions)
16# [{'label': 'building and public works', 'score': 0.9626012444496155}]1from transformers import pipeline
2import numpy as np
3
4# Init feature extraction pipeline
5feature_extraction_pipe = pipeline(task="feature-extraction",
6 model="coastalcph/danish-legal-longformer-eurlex-sd",
7 use_auth_token='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')
8
9# Encode document
10predictions = feature_extraction_pipe("KOMMISSIONENS BESLUTNING\naf 6. marts 2006\nom klassificering af visse byggevarers "
11 "ydeevne med hensyn til reaktion ved brand for så vidt angår trægulve samt vægpaneler "
12 "og vægbeklædning i massivt træ\n(meddelt under nummer K(2006) 655")
13
14# Use CLS token representation as document embedding
15document_features = token_wise_features[0][0]
16
17print(document_features.shape)
18# (768,)