Downloads · 30 days
13
19% of all-time downloads
tobiasnorlund/SWEb-markdown-extractor
SWEb-markdown-extractor is a feature extraction model from tobiasnorlund. Use it when you need embeddings to search or compare text. It is set up for transformers. The card lists the license as apache-2.0.
This model is developed by the NLU team at AI Sweden as a primary content extractor from web pages, and was used to produce the SWEb dataset. For more details, please see the SWEb paper and SWEb source code.
Downloads · 30 days
13
19% of all-time downloads
All-time downloads
70
Public
Parameters
311M
1.3 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors1.2 GB · 99%
From the Hugging Face model README
This model is developed by the NLU team at AI Sweden as a primary content extractor from web pages, and was used to produce the SWEb dataset. For more details, please see the SWEb paper and SWEb source code.
In our source code, you'll find:
The model can be used to extract the primary content from websites. The below example show how it can be used (taken from here):
import os
import requests
from torch.nn.functional import sigmoid
from pipeline.warc_processing import ConvertToMarkdown
from transformers import AutoTokenizer, AutoModelForTokenClassification
# 1. Download a webpage
resp = requests.get("https://www.ai.se/sv/nyheter/nobelpriset-i-fysik-och-kemi-till-banbrytande-ai-forskning")
# 2. Convert HTML to markdown using pandoc
markdown = ConvertToMarkdown.convert_html_to_markdown(resp.content, pandoc_path=f"{os.environ['HOME']}/bin/pandoc") # path to pandoc 2.9.2.1, see INSTALL.md
# 3. Extract text by classifying each line using trained model
tokenizer = AutoTokenizer.from_pretrained("AI-Sweden-Models/SWEb-markdown-extractor")
model = AutoModelForTokenClassification.from_pretrained("AI-Sweden-Models/SWEb-markdown-extractor").eval()
tokens = tokenizer(markdown.replace("\n", tokenizer.sep_token), return_tensors="pt", add_special_tokens=False, truncation=True)
tokens["line_sep_token_ids"] = (tokens.input_ids[0] == tokenizer.sep_token_id).nonzero()[None, :, 0]
logits = model(**tokens)[0]
extracted_lines = [
line for line, pred in zip(markdown.split("\n"), sigmoid(logits))
if pred > 0.05
]
# Print extracted text
print("\n".join(extracted_lines))
outputs:
# Nobelpriset i fysik och kemi till banbrytande AI-forskning
tisdag, oktober 8, 2024
Två Nobelpris till AI 2024\! Det i fysik går till forskning som lagt grunden till maskininlärning och artificiell intelligens, och det i kemi till Google DeepMinds AlphaFold2
*– Det är fantastiskt att det här viktiga arbetet får ett sådant erkännande. Särskilt den tillämpade AI som uppmärksammas i Kemipriset*, säger Johanna Bergman, Director of Strategic Initiatives på AI Sweden.
...
We propose using model based extractors as they provide more flexibility in shaping the extraction through data rather than rules. This model was trained on Scandinavian webpages in particular, so we expect extraction for webpages in these languages to work better than other languages. However, annotating using our tool is swift and the model learns from small amounts of data.
The text extraction model presented here is designed to extract primary content from webpages, but it is important to acknowledge its inherent biases, risks, and limitations. The following aspects should be considered when using this model and the datasets derived from it.
These biases, risks, and limitations emphasize the need for careful curation, filtering, and post-processing of the extracted content to mitigate negative impacts on downstream applications. Users of this model should consider integrating diverse sources, employing bias mitigation techniques, and conducting ongoing evaluations to reduce the potential harms associated with large-scale pretraining.
Please find our training and test data here
Please find our training script here
To cite this work, please use the following:
@misc{norlund2024sweblargewebdataset,
title={SWEb: A Large Web Dataset for the Scandinavian Languages},
author={Tobias Norlund and Tim Isbister and Amaru Cuba Gyllensten and Paul Dos Santos and Danila Petrelli and Ariel Ekgren and Magnus Sahlgren},
year={2024},
eprint={2410.04456},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2410.04456},
}