Repository: nicolay-r/ARElight (language: python)

Issue:
UnitTests



Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index 284e21c..9a7ff3f 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# ARElight 0.22.0
+# ARElight 0.22.1
 
 ### :point_right: [DEMO](#docker-verion-quick) :point_left:
 
@@ -18,8 +18,7 @@ we adopt [DeepPavlov](https://github.com/deepmipt/DeepPavlov)  (BertOntoNotes mo
 
 # Dependencies
 
-* arekit == 0.22.0
-* gensim == 3.2.0
+* arekit == 0.22.1
 * deeppavlov == 0.11.0
 * rusenttokenize
 * brat-v1.3 [[github]](https://github.com/nlplab/brat)
@@ -82,7 +81,7 @@ Infer sentiment attitudes from a mass-media document(s).
 
 Using the `BERT` fine-tuned model version:
 ```bash
-python3.6 infer_texts_bert.py --from-files data/texts-inosmi-rus/e1.txt \
+python3.6 infer_bert.py --from-files data/texts-inosmi-rus/e1.txt \
     --labels-count 3 \
     --terms-per-context 50 \
     --tokens-per-context 128 \
@@ -97,7 +96,7 @@ python3.6 infer_texts_bert.py --from-files data/texts-inosmi-rus/e1.txt \
 
 Using the pretrained `PCNN` model (including frames annotation):
 ```bash
-python3.6 infer_texts_nn.py --from-files data/texts-inosmi-rus/e1.txt \
+python3.6 infer_nn.py --from-files data/texts-inosmi-rus/e1.txt \
     --model-name pcnn \
     --model-state-dir models/ \
     --terms-per-context 50 \
@@ -123,7 +122,7 @@ python3.6 infer_texts_nn.py --from-files data/texts-inosmi-rus/e1.txt \
 
 For the `BERT` model:
 ```bash
-python3.6 serialize_texts_bert.py --from-files data/texts-inosmi-rus/e1.txt 
+python3.6 serialize_bert.py --from-files data/texts-inosmi-rus/e1.txt 
     --entities-parser bert-ontonotes \
     --terms-per-context 50 
 ```
@@ -136,7 +135,7 @@ python3.6 serialize_texts_bert.py --from-files data/texts-inosmi-rus/e1.txt
 
 For the other neural networks (including embedding and other features):
 ```bash
-python3.6 serialize_texts_nn.py --from-files data/texts-inosmi-rus/e1.txt \
+python3.6 serialize_nn.py --from-files data/texts-inosmi-rus/e1.txt \
     --entities-parser bert-ontonotes \
     --stemmer mystem \
     --terms-per-context 50 \
@@ -149,13 +148,6 @@ python3.6 serialize_texts_nn.py --from-files data/texts-inosmi-rus/e1.txt \
     <img src="docs/samples-nn.png"/>
 </p>
 
-# Other Examples
-
-* Serialize RuSentRel collection for BERT [[code]](examples/serialize_rusentrel_for_bert.py)
-* Serialize RuSentRel collection for Neural Networks [[code]](examples/serialize_rusentrel_for_nn.py)
-* Finetune BERT on samples [[code]](examples/train_bert.py)
-* Finetune Neural Networks on RuSentRel [[code]](examples/train_nn_on_rusentrel.py)
-
 # Papers
 
 * [Nicolay Rusnachenko: Language Models Application in Sentiment Attitude Extraction Task (2021) [RUS]](https://nicolay-r.github.io/website/data/rusnachenko2021language.pdf)
diff --git a/arelight/brat_backend.py b/arelight/brat_backend.py
index fddcbd9..37f3b55 100644
--- a/arelight/brat_backend.py
+++ b/arelight/brat_backend.py
@@ -1,18 +1,18 @@
 from tqdm import tqdm
-
 import collections
+
 from os.path import dirname, realpath, join
 
+from arekit.common.context.token import Token
 from arekit.common.data import const
 from arekit.common.data.input.providers.text.single import BaseSingleTextProvider
 from arekit.common.data.storages.base import BaseRowsStorage
 from arekit.common.entities.base import Entity
 from arekit.common.frames.variants.base import FrameVariant
 from arekit.common.news.entity import DocumentEntity
+from arekit.contrib.utils.processing.text.tokens import Tokens
 from arekit.contrib.networks.core.input.const import FrameVariantIndices
 from arekit.contrib.networks.core.input.rows_parser import ParsedSampleRow
-from arekit.processing.text.token import Token
-from arekit.processing.text.tokens import Tokens
 
 
 class BratBackend(object):
diff --git a/arelight/demo/infer_bert_rus.py b/arelight/demo/infer_bert_rus.py
deleted file mode 100644
index c21f902..0000000
--- a/arelight/demo/infer_bert_rus.py
+++ /dev/null
@@ -1,77 +0,0 @@
-from arekit.common.experiment.annot.algo.pair_based import PairBasedAnnotationAlgorithm
-from arekit.common.experiment.annot.default import DefaultAnnotator
-from arekit.common.experiment.data_type import DataType
-from arekit.common.experiment.name_provider import ExperimentNameProvider
-from arekit.common.folding.nofold import NoFolding
-from arekit.common.labels.base import NoLabel
-from arekit.common.labels.provider.constant import ConstantLabelProvider
-from arekit.common.pipeline.base import BasePipeline
-from arekit.contrib.bert.samplers.types import SampleFormattersService
-from arekit.contrib.experiment_rusentrel.entities.factory import create_entity_formatter
-from arekit.contrib.experiment_rusentrel.entities.types import EntityFormatterTypes
-from arekit.contrib.experiment_rusentrel.labels.scalers.three import ThreeLabelScaler
-from arekit.contrib.experiment_rusentrel.labels.types import ExperimentPositiveLabel, ExperimentNegativeLabel
-from arekit.contrib.networks.core.predict.tsv_writer import TsvPredictWriter
-from arekit.processing.lemmatization.mystem import MystemWrapper
-
-from arelight.demo.utils import read_synonyms_collection
-from arelight.pipelines.backend_brat_json import BratBackendContentsPipelineItem
-from arelight.pipelines.inference_bert import BertInferencePipelineItem
-from arelight.pipelines.serialize_bert import BertTextsSerializationPipelineItem
-from arelight.text.pipeline_entities_bert_ontonotes import BertOntonotesNERPipelineItem
-
-
-def demo_infer_texts_bert_pipeline(texts_count,
-                                   synonyms_filepath,
-                                   output_dir,
-                                   bert_config_path,
-                                   bert_vocab_path,
-                                   bert_finetuned_ckpt_path,
-                                   stemmer=MystemWrapper(),
-                                   text_b_type=SampleFormattersService.name_to_type("nli_m"),
-                                   labels_scaler=ThreeLabelScaler(),
-                                   terms_per_context=50,
-                                   do_lowercase=False,
-                                   max_seq_length=128):
-    assert(isinstance(texts_count, int))
-    assert(isinstance(output_dir, str))
-    assert(isinstance(synonyms_filepath, str))
-
-    ppl = BasePipeline(pipeline=[
-
-        BertTextsSerializationPipelineItem(
-            synonyms=read_synonyms_collection(synonyms_filepath=synonyms_filepath, stemmer=stemmer),
-            terms_per_context=terms_per_context,
-            entities_parser=BertOntonotesNERPipelineItem(
-                lambda s_obj: s_obj.ObjectType in ["ORG", "PERSON", "LOC", "GPE"]),
-            entity_fmt=create_entity_formatter(EntityFormatterTypes.HiddenBertStyled),
-            name_provider=ExperimentNameProvider(name="example-bert", suffix="infer"),
-            text_b_type=text_b_type,
-            output_dir=output_dir,
-            opin_annot=DefaultAnnotator(
-                PairBasedAnnotationAlgorithm(
-                    dist_in_terms_bound=None,
-                    label_provider=ConstantLabelProvider(label_instance=NoLabel()))),
-            data_folding=NoFolding(doc_ids_to_fold=list(range(texts_count)),
-                                   supported_data_types=[DataType.Test])),
-
-        BertInferencePipelineItem(
-            data_type=DataType.Test,
-            predict_writer=TsvPredictWriter(),
-            bert_config_file=bert_config_path,
-            model_checkpoint_path=bert_finetuned_ckpt_path,
-            vocab_filepath=bert_vocab_path,
-            max_seq_length=max_seq_length,
-            do_lowercase=do_lowercase,
-            labels_scaler=labels_scaler),
-
-        BratBackendContentsPipelineItem(label_to_rel={
-            str(labels_scaler.label_to_uint(ExperimentPositiveLabel())): "POS",
-            str(labels_scaler.label_to_uint(ExperimentNegativeLabel())): "NEG"
-        },
-            obj_color_types={"ORG": '#7fa2ff', "GPE": "#7fa200", "PERSON": "#7f00ff", "Frame": "#00a2ff"},
-            rel_color_types={"POS": "GREEN", "NEG": "RED"},
-        )
-    ])
-
-    return ppl
diff --git a/arelight/demo/infer_nn_rus.py b/arelight/demo/infer_nn_rus.py
deleted file mode 100644
index c525d3f..0000000
--- a/arelight/demo/infer_nn_rus.py
+++ /dev/null
@@ -1,97 +0,0 @@
-from arekit.common.experiment.annot.algo.pair_based import PairBasedAnnotationAlgorithm
-from arekit.common.experiment.annot.default import DefaultAnnotator
-from arekit.common.experiment.data_type import DataType
-from arekit.common.experiment.name_provider import ExperimentNameProvider
-from arekit.common.folding.nofold import NoFolding
-from arekit.common.labels.base import NoLabel
-from arekit.common.labels.provider.constant import ConstantLabelProvider
-from arekit.common.pipeline.base import BasePipeline
-from arekit.contrib.experiment_rusentrel.entities.factory import create_entity_formatter
-from arekit.contrib.experiment_rusentrel.entities.types import EntityFormattersService
-from arekit.contrib.experiment_rusentrel.labels.scalers.three import ThreeLabelScaler
-from arekit.contrib.experiment_rusentrel.labels.types import ExperimentPositiveLabel, ExperimentNegativeLabel
-from arekit.contrib.networks.core.callback.stat import TrainingStatProviderCallback
-from arekit.contrib.networks.core.callback.train_limiter import TrainingLimiterCallback
-from arekit.contrib.networks.core.predict.tsv_writer import TsvPredictWriter
-from arekit.contrib.networks.enum_name_types import ModelNames
-from arekit.processing.lemmatization.mystem import MystemWrapper
-
-from arelight.demo.utils import read_synonyms_collection
-from arelight.network.nn.common import create_network_model_io, create_bags_collection_type, create_full_model_name
-from arelight.pipelines.backend_brat_json import BratBackendContentsPipelineItem
-from arelight.pipelines.inference_nn import TensorflowNetworkInferencePipelineItem
-from arelight.pipelines.serialize_nn import NetworkTextsSerializationPipelineItem
-from arelight.text.pipeline_entities_bert_ontonotes import BertOntonotesNERPipelineItem
-
-
-def demo_infer_texts_tensorflow_nn_pipeline(texts_count,
-                                            model_name, model_input_type, model_load_dir,
-                                            frames_collection,
-                                            output_dir,
-                                            synonyms_filepath,
-                                            embedding_filepath,
-                                            embedding_matrix_filepath=None,
-                                            vocab_filepath=None,
-                                            bags_per_minibatch=2,
-                                            entity_fmt_type=EntityFormattersService.name_to_type("hidden-simple-eng"),
-                                            exp_name_provider=ExperimentNameProvider(name="example", suffix="infer"),
-                                            stemmer=MystemWrapper(),
-                                            labels_scaler=ThreeLabelScaler(),
-                                            terms_per_context=50):
-    assert(isinstance(texts_count, int))
-    assert(isinstance(model_name, ModelNames))
-
-    nn_io = create_network_model_io(
-        full_model_name=create_full_model_name(model_name=model_name, input_type=model_input_type),
-        embedding_filepath=embedding_matrix_filepath,
-        source_dir=model_load_dir,
-        target_dir=model_load_dir,
-        vocab_filepath=vocab_filepath,
-        model_name_tag=u'')
-
-    # Declaring pipeline.
-    ppl = BasePipeline(pipeline=[
-
-        NetworkTextsSerializationPipelineItem(
-            frames_collection=frames_collection,
-            synonyms=read_synonyms_collection(synonyms_filepath=synonyms_filepath, stemmer=stemmer),
-            terms_per_context=terms_per_context,
-            embedding_path=embedding_filepath,
-            entities_parser=BertOntonotesNERPipelineItem(
-                lambda s_obj: s_obj.ObjectType in ["ORG", "PERSON", "LOC", "GPE"]),
-            entity_fmt=create_entity_formatter(entity_fmt_type),
-            stemmer=stemmer,
-            name_provider=exp_name_provider,
-            opin_annot=DefaultAnnotator(
-                PairBasedAnnotationAlgorithm(
-                    dist_in_terms_bound=None,
-                    label_provider=ConstantLabelProvider(label_instance=NoLabel()))),
-            output_dir=output_dir,
-            data_folding=NoFolding(doc_ids_to_fold=list(range(texts_count)),
-                                   supported_data_types=[DataType.Test])),
-
-        TensorflowNetworkInferencePipelineItem(
-            nn_io=nn_io,
-            model_name=model_name,
-            data_type=DataType.Test,
-            bag_size=1,
-            bags_per_minibatch=bags_per_minibatch,
-            bags_collection_type=create_bags_collection_type(model_input_type=model_input_type),
-            model_input_type=model_input_type,
-            labels_scaler=labels_scaler,
-            predict_writer=TsvPredictWriter(),
-            callbacks=[
-                TrainingLimiterCallback(train_acc_limit=0.99),
-                TrainingStatProviderCallback(),
-            ]),
-
-        BratBackendContentsPipelineItem(label_to_rel={
-            str(labels_scaler.label_to_uint(ExperimentPositiveLabel())): "POS",
-            str(labels_scaler.label_to_uint(ExperimentNegativeLabel())): "NEG"
-        },
-            obj_color_types={"ORG": '#7fa2ff', "GPE": "#7fa200", "PERSON": "#7f00ff", "Frame": "#00a2ff"},
-            rel_color_types={"POS": "GREEN", "NEG": "RED"},
-        ),
-    ])
-
-    return ppl
diff --git a/arelight/doc_ops.py b/arelight/doc_ops.py
new file mode 100644
index 0000000..dbe34ca
--- /dev/null
+++ b/arelight/doc_ops.py
@@ -0,0 +1,15 @@
+from arekit.common.experiment.api.ops_doc import DocumentOperations
+
+
+class InMemoryDocOperations(DocumentOperations):
+
+    def __init__(self, docs=None):
+        assert(isinstance(docs, list) or docs is None)
+        self.__docs = docs
+
+    def set_docs(self, docs):
+        assert(isinstance(docs, list))
+        self.__docs = docs
+
+    def get_doc(self, doc_id):
+        return self.__docs[doc_id]
diff --git a/arelight/exp/doc_ops.py b/arelight/exp/doc_ops.py
deleted file mode 100644
index 2f7e375..0000000
--- a/arelight/exp/doc_ops.py
+++ /dev/null
@@ -1,23 +0,0 @@
-from arekit.common.experiment.api.enums import BaseDocumentTag
-from arekit.common.experiment.api.ops_doc import DocumentOperations
-
-
-class CustomDocOperations(DocumentOperations):
-
-    def iter_tagget_doc_ids(self, tag):
-        assert(isinstance(tag, BaseDocumentTag))
-        assert(tag == BaseDocumentTag.Annotate)
-        return self.__doc_ids
-
-    def __init__(self, exp_ctx, text_parser):
-        super(CustomDocOperations, self).__init__(exp_ctx, text_parser)
-        self.__docs = None
-        self.__doc_ids = None
-
-    def set_docs(self, docs):
-        assert(isinstance(docs, list))
-        self.__docs = docs
-        self.__doc_ids = list(range(len(self.__docs)))
-
-    def get_doc(self, doc_id):
-        return self.__docs[doc_id]
diff --git a/arelight/exp/exp_io.py b/arelight/exp/exp_io.py
deleted file mode 100644
index 962fe03..0000000
--- a/arelight/exp/exp_io.py
+++ /dev/null
@@ -1,23 +0,0 @@
-import os
-from arekit.contrib.experiment_rusentrel.model_io.tf_networks import RuSentRelExperimentNetworkIOUtils
-
-
-class InferIOUtils(RuSentRelExperimentNetworkIOUtils):
-
-    def __init__(self, output_dir, exp_ctx):
-        assert(isinstance(output_dir, str))
-        super(InferIOUtils, self).__init__(exp_ctx=exp_ctx)
-        self.__output_dir = output_dir
-
-    def __create_annot_input_target(self, doc_id, data_type):
-        filename = "annot_input_d{doc_id}_{data_type}.txt".format(doc_id=doc_id, data_type=data_type.name)
-        return os.path.join(self._get_target_dir(), filename)
-
-    def _get_experiment_sources_dir(self):
-        return self.__output_dir
-
-    def create_opinion_collection_target(self, doc_id, data_type, check_existance=False):
-        return self.__create_annot_input_target(doc_id=doc_id, data_type=data_type)
-
-    def create_result_opinion_collection_target(self, doc_id, data_type, epoch_index):
-        return self.__create_annot_input_target(doc_id=doc_id, data_type=data_type)
diff --git a/arelight/exp/opin_ops.py b/arelight/exp/opin_ops.py
deleted file mode 100644
index ba6eac8..0000000
--- a/arelight/exp/opin_ops.py
+++ /dev/null
@@ -1,39 +0,0 @@
-from arekit.common.experiment.api.ops_opin import OpinionOperations
-from arekit.common.opinions.collection import OpinionCollection
-
-
-class CustomOpinionOperations(OpinionOperations):
-
-    def __init__(self, labels_formatter, exp_io, synonyms, neutral_labels_fmt):
-        super(CustomOpinionOperations, self).__init__()
-        self.__labels_formatter = labels_formatter
-        self.__exp_io = exp_io
-        self.__synonyms = synonyms
-        self.__neutral_labels_fmt = neutral_labels_fmt
-
-    @property
-    def LabelsFormatter(self):
-        return self.__labels_formatter
-
-    def iter_opinions_for_extraction(self, doc_id, data_type):
-        # Reading automatically annotated collection of neutral opinions.
-        # TODO. #250, #251 provide opinion annotation here for the particular document.
-        return self.__exp_io.read_opinion_collection(
-            target=self.__exp_io.create_result_opinion_collection_target(
-                doc_id=doc_id,
-                data_type=data_type,
-                epoch_index=0),
-            labels_formatter=self.__neutral_labels_fmt,
-            create_collection_func=self.create_opinion_collection)
-
-    def get_etalon_opinion_collection(self, doc_id):
-        return self.create_opinion_collection(None)
-
-    def get_result_opinion_collection(self, doc_id, data_type, epoch_index):
-        raise Exception("Not Supported")
-
-    def create_opinion_collection(self, opinions=None):
-        return OpinionCollection(opinions=[] if opinions is None else opinions,
-                                 synonyms=self.__synonyms,
-                                 error_on_duplicates=True,
-                                 error_on_synonym_end_missed=True)
diff --git a/arelight/demo/__init__.py b/arelight/ner/__init__.py
similarity index 100%
rename from arelight/demo/__init__.py
rename to arelight/ner/__init__.py
diff --git a/arelight/text/ner_base.py b/arelight/ner/base.py
similarity index 97%
rename from arelight/text/ner_base.py
rename to arelight/ner/base.py
index d3e6946..88d0e38 100644
--- a/arelight/text/ner_base.py
+++ b/arelight/ner/base.py
@@ -1,4 +1,4 @@
-from arekit.processing.entities.obj_desc import NerObjectDescriptor
+from arelight.ner.obj_desc import NerObjectDescriptor
 
 
 class BaseNER(object):
diff --git a/arelight/ner/obj_desc.py b/arelight/ner/obj_desc.py
new file mode 100644
index 0000000..50796ef
--- /dev/null
+++ b/arelight/ner/obj_desc.py
@@ -0,0 +1,21 @@
+class NerObjectDescriptor:
+
+    def __init__(self, pos, length, obj_type):
+        self.__pos = pos
+        self.__len = length
+        self.__obj_type = obj_type
+
+    @property
+    def Position(self):
+        return self.__pos
+
+    @property
+    def Length(self):
+        return self.__len
+
+    @property
+    def ObjectType(self):
+        return self.__obj_type
+
+    def get_range(self):
+        return self.__pos, self.__pos + self.__len
\ No newline at end of file
diff --git a/arelight/text/ner_ontonotes.py b/arelight/ner/ontonotes.py
similarity index 97%
rename from arelight/text/ner_ontonotes.py
rename to arelight/ner/ontonotes.py
index be8486b..29946db 100644
--- a/arelight/text/ner_ontonotes.py
+++ b/arelight/ner/ontonotes.py
@@ -1,6 +1,6 @@
 import importlib
 
-from arelight.text.ner_base import BaseNER
+from arelight.ner.base import BaseNER
 
 
 class BertOntonotesNER(BaseNER):
diff --git a/arelight/network/bert/ctx.py b/arelight/network/bert/ctx.py
deleted file mode 100644
index 5d04c38..0000000
--- a/arelight/network/bert/ctx.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from arekit.common.entities.str_fmt import StringEntitiesFormatter
-from arekit.common.experiment.api.ctx_serialization import ExperimentSerializationContext
-
-
-class BertSerializationContext(ExperimentSerializationContext):
-
-    def __init__(self, label_scaler, terms_per_context, str_entity_formatter,
-                 annotator, name_provider, data_folding):
-        assert(isinstance(str_entity_formatter, StringEntitiesFormatter))
-        assert(isinstance(terms_per_context, int))
-
-        super(BertSerializationContext, self).__init__(annot=annotator,
-                                                       name_provider=name_provider,
-                                                       label_scaler=label_scaler,
-                                                       data_folding=data_folding)
-
-        self.__terms_per_context = terms_per_context
-        self.__str_entity_formatter = str_entity_formatter
-
-    @property
-    def StringEntityFormatter(self):
-        return self.__str_entity_formatter
-
-    @property
-    def TermsPerContext(self):
-        return self.__terms_per_context
diff --git a/arelight/network/nn/common.py b/arelight/network/nn/common.py
index aa97d52..d88bad5 100644
--- a/arelight/network/nn/common.py
+++ b/arelight/network/nn/common.py
@@ -1,8 +1,6 @@
-from arekit.common.folding.types import FoldingType
 from arekit.common.frames.variants.collection import FrameVariantsCollection
 from arekit.contrib.networks.core.feeding.bags.collection.multi import MultiInstanceBagsCollection
 from arekit.contrib.networks.core.feeding.bags.collection.single import SingleBagsCollection
-from arekit.contrib.networks.core.model_io import NeuralNetworkModelIO
 from arekit.contrib.networks.enum_input_types import ModelInputType
 from arekit.contrib.networks.enum_name_types import ModelNames
 
@@ -27,27 +25,6 @@ def create_bags_collection_type(model_input_type):
         return MultiInstanceBagsCollection
 
 
-def create_network_model_io(full_model_name, source_dir, embedding_filepath,
-                            target_dir, vocab_filepath, model_name_tag):
-
-    return NeuralNetworkModelIO(full_model_name=full_model_name,
-                                target_dir=target_dir,
-                                source_dir=source_dir,
-                                embedding_filepath=embedding_filepath,
-                                vocab_filepath=vocab_filepath,
-                                model_name_tag=model_name_tag)
-
-
-def __create_folding_type_prefix(folding_type):
-    assert(isinstance(folding_type,  FoldingType))
-    if folding_type == FoldingType.Fixed:
-        return u'fx'
-    elif folding_type == FoldingType.CrossValidation:
-        return u'cv'
-    else:
-        raise NotImplementedError(u"Folding type `{}` was not declared".format(folding_type))
-
-
 def __create_input_type_prefix(input_type):
     assert(isinstance(input_type, ModelInputType))
     if input_type == ModelInputType.SingleInstance:
@@ -62,6 +39,4 @@ def __create_input_type_prefix(input_type):
 
 def create_full_model_name(model_name, input_type):
     assert(isinstance(model_name, ModelNames))
-    return u'_'.join([__create_folding_type_prefix(FoldingType.Fixed),
-                      __create_input_type_prefix(input_type),
-                      model_name.value])
+    return u'_'.join([u'fx', __create_input_type_prefix(input_type), model_name.value])
diff --git a/arelight/network/nn/ctx.py b/arelight/network/nn/ctx.py
index 2be9dfc..038c841 100644
--- a/arelight/network/nn/ctx.py
+++ b/arelight/network/nn/ctx.py
@@ -1,33 +1,21 @@
-from arekit.common.entities.str_fmt import StringEntitiesFormatter
-from arekit.contrib.experiment_rusentrel.connotations.provider import RuSentiFramesConnotationProvider
-from arekit.contrib.experiment_rusentrel.labels.scalers.three import ThreeLabelScaler
 from arekit.contrib.networks.core.input.ctx_serialization import NetworkSerializationContext
-from arekit.contrib.networks.embeddings.base import Embedding
 from arekit.contrib.source.rusentiframes.collection import RuSentiFramesCollection
-from arekit.processing.pos.base import POSTagger
+from arekit.contrib.utils.connotations.rusentiframes_sentiment import RuSentiFramesConnotationProvider
+from arekit.contrib.utils.processing.pos.base import POSTagger
 
+from arelight.pipelines.demo.labels.scalers import ThreeLabelScaler
 
-class NetworkSerializationContext(NetworkSerializationContext):
 
-    def __init__(self, labels_scaler, pos_tagger, embedding,
-                 terms_per_context, str_entity_formatter, annotator,
-                 frames_collection, frame_variant_collection, name_provider, data_folding):
-        assert(isinstance(embedding, Embedding))
+class CustomNeuralNetworkSerializationContext(NetworkSerializationContext):
+
+    def __init__(self, labels_scaler, pos_tagger, frames_collection):
         assert(isinstance(pos_tagger, POSTagger))
         assert(isinstance(frames_collection, RuSentiFramesCollection))
-        assert(isinstance(str_entity_formatter, StringEntitiesFormatter))
-        assert(isinstance(terms_per_context, int))
 
-        super(NetworkSerializationContext, self).__init__(
-            labels_scaler=labels_scaler, annot=annotator,
-            name_provider=name_provider, data_folding=data_folding)
+        super(CustomNeuralNetworkSerializationContext, self).__init__(labels_scaler=labels_scaler)
 
         self.__pos_tagger = pos_tagger
-        self.__terms_per_context = terms_per_context
-        self.__str_entity_formatter = str_entity_formatter
-        self.__word_embedding = embedding
         self.__frames_collection = frames_collection
-        self.__frame_variant_collection = frame_variant_collection
         self.__frame_roles_label_scaler = ThreeLabelScaler()
         self.__frames_connotation_provider = RuSentiFramesConnotationProvider(collection=self.__frames_collection)
 
@@ -35,26 +23,6 @@ def __init__(self, labels_scaler, pos_tagger, embedding,
     def PosTagger(self):
         return self.__pos_tagger
 
-    @property
-    def StringEntityFormatter(self):
-        return self.__str_entity_formatter
-
-    @property
-    def StringEntityEmbeddingFormatter(self):
-        return self.__str_entity_formatter
-
-    @property
-    def FrameVariantCollection(self):
-        return self.__frame_variant_collection
-
-    @property
-    def WordEmbedding(self):
-        return self.__word_embedding
-
-    @property
-    def TermsPerContext(self):
-        return self.__terms_per_context
-
     @property
     def FramesConnotationProvider(self):
         return self.__frames_connotation_provider
diff --git a/arelight/network/nn/embedding.py b/arelight/network/nn/embedding.py
deleted file mode 100644
index 4ebbf69..0000000
--- a/arelight/network/nn/embedding.py
+++ /dev/null
@@ -1,69 +0,0 @@
-import numpy as np
-from arekit.common.text.stemmer import Stemmer
-from arekit.contrib.networks.embeddings.base import Embedding
-from gensim.models import KeyedVectors
-
-
-class RusvectoresEmbedding(Embedding):
-
-    def __init__(self, matrix, words):
-        super(RusvectoresEmbedding, self).__init__(matrix=matrix,
-                                                   words=words)
-
-        self.__index_without_pos = self.__create_terms_without_pos()
-        self.__stemmer = None
-        self.__lemmatize_by_default = True
-
-    @classmethod
-    def from_word2vec_format(cls, filepath, binary):
-        assert(isinstance(binary, bool))
-
-        w2v_model = KeyedVectors.load_word2vec_format(filepath, binary=binary)
-        words_count = len(w2v_model.wv.vocab)
-
-        return cls(matrix=np.array([vector for vector in w2v_model.syn0]),
-                   words=[w2v_model.wv.index2word[index] for index in range(words_count)])
-
-    def set_stemmer(self, stemmer):
-        assert(isinstance(stemmer, Stemmer))
-        self.__stemmer = stemmer
-
-    def try_find_index_by_plain_word(self, word):
-        assert(isinstance(word, str))
-
-        temp = self.__lemmatize_by_default
-        self.__lemmatize_by_default = False
-        index = super(RusvectoresEmbedding, self).try_find_index_by_plain_word(word)
-        self.__lemmatize_by_default = temp
-
-        return index
-
-    def _handler(self, word):
-        return self.__try_find_word_index_pair_lemmatized(word, self.__lemmatize_by_default)
-
-    # region private methods
-
-    def __try_find_word_index_pair_lemmatized(self, term, lemmatize):
-        assert(isinstance(term, str))
-        assert(isinstance(lemmatize, bool))
-
-        if lemmatize:
-            term = self.__stemmer.lemmatize_to_str(term)
-
-        index = self.__index_without_pos[term] \
-            if term in self.__index_without_pos else None
-
-        return term, index
-
-    def __create_terms_without_pos(self):
-        d = {}
-        for word_with_pos, index in self.iter_vocabulary():
-            assert(isinstance(word_with_pos, str))
-            word = word_with_pos.split(u'_')[0]
-            if word in d:
-                continue
-            d[word] = index
-
-        return d
-
-    # endregion
\ No newline at end of file
diff --git a/arelight/pipelines/annot_nolabel.py b/arelight/pipelines/annot_nolabel.py
new file mode 100644
index 0000000..aea6995
--- /dev/null
+++ b/arelight/pipelines/annot_nolabel.py
@@ -0,0 +1,39 @@
+from arekit.common.labels.base import NoLabel
+from arekit.common.labels.provider.constant import ConstantLabelProvider
+from arekit.common.opinions.annot.algo.pair_based import PairBasedOpinionAnnotationAlgorithm
+from arekit.common.opinions.collection import OpinionCollection
+from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
+from arekit.contrib.utils.pipelines.text_opinion.annot.algo_based import AlgorithmBasedTextOpinionAnnotator
+from arekit.contrib.utils.pipelines.text_opinion.extraction import text_opinion_extraction_pipeline
+from arekit.contrib.utils.pipelines.text_opinion.filters.distance_based import DistanceLimitedTextOpinionFilter
+
+
+def create_neutral_annotation_pipeline(synonyms, dist_in_terms_bound, terms_per_context,
+                                       doc_ops, text_parser, dist_in_sentences=0):
+
+    nolabel_annotator = AlgorithmBasedTextOpinionAnnotator(
+        value_to_group_id_func=lambda value:
+            SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
+                synonyms=synonyms, value=value),
+        annot_algo=PairBasedOpinionAnnotationAlgorithm(
+            dist_in_sents=dist_in_sentences,
+            dist_in_terms_bound=dist_in_terms_bound,
+            label_provider=ConstantLabelProvider(NoLabel())),
+        create_empty_collection_func=lambda: OpinionCollection(
+            opinions=[],
+            synonyms=synonyms,
+            error_on_duplicates=True,
+            error_on_synonym_end_missed=False),
+        get_doc_existed_opinions_func=lambda _: None)
+
+    annotation_pipeline = text_opinion_extraction_pipeline(
+        text_parser=text_parser,
+        get_doc_func=lambda doc_id: doc_ops.get_doc(doc_id),
+        annotators=[
+            nolabel_annotator
+        ],
+        text_opinion_filters=[
+            DistanceLimitedTextOpinionFilter(terms_per_context)
+        ])
+
+    return annotation_pipeline
diff --git a/arelight/exp/__init__.py b/arelight/pipelines/demo/__init__.py
similarity index 100%
rename from arelight/exp/__init__.py
rename to arelight/pipelines/demo/__init__.py
diff --git a/arelight/pipelines/demo/infer_bert_rus.py b/arelight/pipelines/demo/infer_bert_rus.py
new file mode 100644
index 0000000..b95204d
--- /dev/null
+++ b/arelight/pipelines/demo/infer_bert_rus.py
@@ -0,0 +1,67 @@
+from arekit.common.experiment.data_type import DataType
+from arekit.common.labels.base import NoLabel
+from arekit.common.labels.scaler.base import BaseLabelScaler
+from arekit.common.labels.str_fmt import StringLabelsFormatter
+from arekit.common.pipeline.base import BasePipeline
+from arekit.contrib.networks.core.predict.tsv_writer import TsvPredictWriter
+from arekit.contrib.utils.io_utils.samples import SamplesIO
+from arekit.contrib.utils.pipelines.items.sampling.bert import BertExperimentInputSerializerPipelineItem
+
+from arelight.pipelines.demo.labels.base import PositiveLabel, NegativeLabel
+from arelight.pipelines.items.backend_brat_json import BratBackendContentsPipelineItem
+from arelight.pipelines.items.inference_bert import BertInferencePipelineItem
+from arelight.samplers.bert import create_bert_sample_provider
+from arelight.samplers.types import SampleFormattersService
+
+
+def demo_infer_texts_bert_pipeline(texts_count,
+                                   output_dir,
+                                   bert_config_path,
+                                   bert_vocab_path,
+                                   bert_finetuned_ckpt_path,
+                                   entity_fmt,
+                                   labels_scaler,
+                                   text_b_type=SampleFormattersService.name_to_type("nli_m"),
+                                   do_lowercase=False,
+                                   max_seq_length=128):
+    assert(isinstance(texts_count, int))
+    assert(isinstance(output_dir, str))
+    assert(isinstance(labels_scaler, BaseLabelScaler))
+
+    labels_fmt = StringLabelsFormatter(stol={"neu": NoLabel})
+
+    samples_io = SamplesIO(target_dir=output_dir)
+
+    pipeline = BasePipeline(pipeline=[
+
+        BertExperimentInputSerializerPipelineItem(
+            sample_rows_provider=create_bert_sample_provider(
+                provider_type=text_b_type,
+                label_scaler=labels_scaler,
+                text_b_labels_fmt=labels_fmt,
+                entity_formatter=entity_fmt),
+            samples_io=samples_io,
+            save_labels_func=lambda data_type: data_type != DataType.Test,
+            balance_func=lambda data_type: data_type == DataType.Train),
+
+        BertInferencePipelineItem(
+            data_type=DataType.Test,
+            samples_io=samples_io,
+            predict_writer=TsvPredictWriter(),
+            bert_config_file=bert_config_path,
+            model_checkpoint_path=bert_finetuned_ckpt_path,
+            vocab_filepath=bert_vocab_path,
+            max_seq_length=max_seq_length,
+            do_lowercase=do_lowercase,
+            labels_scaler=labels_scaler),
+
+        BratBackendContentsPipelineItem(label_to_rel={
+            str(labels_scaler.label_to_uint(PositiveLabel())): "POS",
+            str(labels_scaler.label_to_uint(NegativeLabel())): "NEG"
+        },
+            obj_color_types={"ORG": '#7fa2ff', "GPE": "#7fa200", "PERSON": "#7f00ff", "Frame": "#00a2ff"},
+            rel_color_types={"POS": "GREEN", "NEG": "RED"},
+        )
+    ])
+
+    return pipeline
diff --git a/arelight/pipelines/demo/infer_nn_rus.py b/arelight/pipelines/demo/infer_nn_rus.py
new file mode 100644
index 0000000..6e501f6
--- /dev/null
+++ b/arelight/pipelines/demo/infer_nn_rus.py
@@ -0,0 +1,109 @@
+from arekit.common.experiment.data_type import DataType
+from arekit.common.labels.base import NoLabel
+from arekit.common.labels.provider.constant import ConstantLabelProvider
+from arekit.common.opinions.annot.algo.pair_based import PairBasedOpinionAnnotationAlgorithm
+from arekit.common.pipeline.base import BasePipeline
+from arekit.contrib.networks.core.callback.stat import TrainingStatProviderCallback
+from arekit.contrib.networks.core.callback.train_limiter import TrainingLimiterCallback
+from arekit.contrib.networks.core.input.term_types import TermTypes
+from arekit.contrib.networks.core.model_io import NeuralNetworkModelIO
+from arekit.contrib.networks.core.predict.tsv_writer import TsvPredictWriter
+from arekit.contrib.networks.enum_name_types import ModelNames
+from arekit.contrib.utils.io_utils.embedding import NpEmbeddingIO
+from arekit.contrib.utils.io_utils.samples import SamplesIO
+from arekit.contrib.utils.pipelines.items.sampling.networks import NetworksInputSerializerPipelineItem
+from arekit.contrib.utils.processing.lemmatization.mystem import MystemWrapper
+from arekit.contrib.utils.processing.pos.mystem_wrap import POSMystemWrapper
+from arekit.contrib.utils.resources import load_embedding_news_mystem_skipgram_1000_20_2015
+from arekit.contrib.utils.vectorizers.bpe import BPEVectorizer
+from arekit.contrib.utils.vectorizers.random_norm import RandomNormalVectorizer
+
+from arelight.network.nn.common import create_bags_collection_type, create_full_model_name
+from arelight.network.nn.ctx import CustomNeuralNetworkSerializationContext
+from arelight.pipelines.demo.labels.base import PositiveLabel, NegativeLabel
+from arelight.pipelines.demo.labels.scalers import ThreeLabelScaler
+from arelight.pipelines.items.backend_brat_json import BratBackendContentsPipelineItem
+from arelight.pipelines.items.inference_nn import TensorflowNetworkInferencePipelineItem
+
+
+def demo_infer_texts_tensorflow_nn_pipeline(texts_count,
+                                            model_name,
+                                            model_input_type,
+                                            model_load_dir,
+                                            output_dir,
+                                            entity_fmt,
+                                            frames_collection,
+                                            bags_per_minibatch=2,
+                                            labels_scaler=ThreeLabelScaler()):
+    assert(isinstance(texts_count, int))
+    assert(isinstance(model_name, ModelNames))
+
+    nn_io = NeuralNetworkModelIO(
+        full_model_name=create_full_model_name(model_name=model_name, input_type=model_input_type),
+        source_dir=model_load_dir,
+        target_dir=model_load_dir,
+        model_name_tag=u'')
+
+    PairBasedOpinionAnnotationAlgorithm(
+        dist_in_terms_bound=None,
+        label_provider=ConstantLabelProvider(label_instance=NoLabel()))
+
+    stemmer = MystemWrapper()
+    embedding = load_embedding_news_mystem_skipgram_1000_20_2015(stemmer)
+    bpe_vectorizer = BPEVectorizer(embedding=embedding, max_part_size=3)
+    norm_vectorizer = RandomNormalVectorizer(vector_size=embedding.VectorSize,
+                                             token_offset=12345)
+
+    ctx = CustomNeuralNetworkSerializationContext(
+        labels_scaler=labels_scaler,
+        pos_tagger=POSMystemWrapper(stemmer.MystemInstance),
+        frames_collection=frames_collection)
+
+    samples_io = SamplesIO(target_dir=output_dir)
+    emb_io = NpEmbeddingIO(target_dir=output_dir)
+
+    # Declaring pipeline.
+    pipeline = BasePipeline(pipeline=[
+
+        NetworksInputSerializerPipelineItem(
+            vectorizers={
+                TermTypes.WORD: bpe_vectorizer,
+                TermTypes.ENTITY: bpe_vectorizer,
+                TermTypes.FRAME: bpe_vectorizer,
+                TermTypes.TOKEN: norm_vectorizer
+            },
+            ctx=ctx,
+            str_entity_fmt=entity_fmt,
+            samples_io=samples_io,
+            emb_io=emb_io,
+            save_labels_func=lambda data_type: data_type != DataType.Test,
+            balance_func=lambda data_type: data_type == DataType.Train,
+            save_embedding=True),
+
+        TensorflowNetworkInferencePipelineItem(
+            nn_io=nn_io,
+            emb_io=emb_io,
+            samples_io=samples_io,
+            model_name=model_name,
+            data_type=DataType.Test,
+            bag_size=1,
+            bags_per_minibatch=bags_per_minibatch,
+            bags_collection_type=create_bags_collection_type(model_input_type=model_input_type),
+            model_input_type=model_input_type,
+            labels_scaler=labels_scaler,
+            predict_writer=TsvPredictWriter(),
+            callbacks=[
+                TrainingLimiterCallback(train_acc_limit=0.99),
+                TrainingStatProviderCallback(),
+            ]),
+
+        BratBackendContentsPipelineItem(label_to_rel={
+            str(labels_scaler.label_to_uint(PositiveLabel())): "POS",
+            str(labels_scaler.label_to_uint(NegativeLabel())): "NEG"
+        },
+            obj_color_types={"ORG": '#7fa2ff', "GPE": "#7fa200", "PERSON": "#7f00ff", "Frame": "#00a2ff"},
+            rel_color_types={"POS": "GREEN", "NEG": "RED"},
+        ),
+    ])
+
+    return pipeline
diff --git a/arelight/network/bert/__init__.py b/arelight/pipelines/demo/labels/__init__.py
similarity index 100%
rename from arelight/network/bert/__init__.py
rename to arelight/pipelines/demo/labels/__init__.py
diff --git a/arelight/pipelines/demo/labels/base.py b/arelight/pipelines/demo/labels/base.py
new file mode 100644
index 0000000..63d0a2c
--- /dev/null
+++ b/arelight/pipelines/demo/labels/base.py
@@ -0,0 +1,10 @@
+from arekit.common.labels.base import Label
+
+
+class PositiveLabel(Label):
+    pass
+
+
+class NegativeLabel(Label):
+    pass
+
diff --git a/arelight/pipelines/demo/labels/scalers.py b/arelight/pipelines/demo/labels/scalers.py
new file mode 100644
index 0000000..7e0ace8
--- /dev/null
+++ b/arelight/pipelines/demo/labels/scalers.py
@@ -0,0 +1,26 @@
+from collections import OrderedDict
+
+from arekit.common.labels.base import NoLabel
+from arekit.common.labels.scaler.sentiment import SentimentLabelScaler
+
+from arelight.pipelines.demo.labels.base import PositiveLabel, NegativeLabel
+
+
+class ThreeLabelScaler(SentimentLabelScaler):
+
+    def __init__(self):
+
+        uint_labels = [(NoLabel(), 0),
+                       (PositiveLabel(), 1),
+                       (NegativeLabel(), 2)]
+
+        int_labels = [(NoLabel(), 0),
+                      (PositiveLabel(), 1),
+                      (NegativeLabel(), -1)]
+
+        super(ThreeLabelScaler, self).__init__(uint_dict=OrderedDict(uint_labels),
+                                               int_dict=OrderedDict(int_labels))
+
+    def invert_label(self, label):
+        int_label = self.label_to_int(label)
+        return self.int_to_label(-int_label)
\ No newline at end of file
diff --git a/arelight/demo/utils.py b/arelight/pipelines/demo/utils.py
similarity index 75%
rename from arelight/demo/utils.py
rename to arelight/pipelines/demo/utils.py
index bf769ab..89a67e5 100644
--- a/arelight/demo/utils.py
+++ b/arelight/pipelines/demo/utils.py
@@ -1,6 +1,6 @@
 from arekit.common.text.stemmer import Stemmer
-from arekit.contrib.experiment_rusentrel.synonyms.collection import StemmerBasedSynonymCollection
-from arekit.contrib.source.rusentrel.utils import iter_synonym_groups
+from arekit.contrib.source.synonyms.utils import iter_synonym_groups
+from arekit.contrib.utils.synonyms.stemmer_based import StemmerBasedSynonymCollection
 
 
 def iter_groups(filepath):
diff --git a/arelight/text/__init__.py b/arelight/pipelines/items/__init__.py
similarity index 100%
rename from arelight/text/__init__.py
rename to arelight/pipelines/items/__init__.py
diff --git a/arelight/pipelines/backend_brat_html.py b/arelight/pipelines/items/backend_brat_html.py
similarity index 100%
rename from arelight/pipelines/backend_brat_html.py
rename to arelight/pipelines/items/backend_brat_html.py
diff --git a/arelight/pipelines/backend_brat_json.py b/arelight/pipelines/items/backend_brat_json.py
similarity index 72%
rename from arelight/pipelines/backend_brat_json.py
rename to arelight/pipelines/items/backend_brat_json.py
index 702e7f1..6869e82 100644
--- a/arelight/pipelines/backend_brat_json.py
+++ b/arelight/pipelines/items/backend_brat_json.py
@@ -1,11 +1,11 @@
-import os
+from os.path import dirname
 
 from arekit.common.experiment.data_type import DataType
 from arekit.common.pipeline.context import PipelineContext
 from arekit.common.pipeline.items.base import BasePipelineItem
+from arekit.contrib.utils.io_utils.samples import SamplesIO
 
 from arelight.brat_backend import BratBackend
-from arelight.exp.exp_io import InferIOUtils
 
 
 class BratBackendContentsPipelineItem(BasePipelineItem):
@@ -19,18 +19,20 @@ def __init__(self, obj_color_types, rel_color_types,
         self.__label_to_rel = label_to_rel
 
     def apply_core(self, input_data, pipeline_ctx):
-        assert(isinstance(input_data, InferIOUtils))
+        assert(isinstance(input_data, SamplesIO))
         assert(isinstance(pipeline_ctx, PipelineContext))
 
+        samples_filepath = input_data.create_target(data_type=DataType.Test,
+                                                    data_folding=pipeline_ctx.provide("data_folding"))
+
         contents = self.__brat_be.to_data(
            result_data_filepath=pipeline_ctx.provide("predict_fp"),
-           samples_data_filepath=input_data.create_samples_writer_target(DataType.Test),
+           samples_data_filepath=samples_filepath,
            obj_color_types=self.__obj_color_types,
            rel_color_types=self.__rel_color_types,
            label_to_rel=self.__label_to_rel)
 
-        exp_root = os.path.join(input_data._get_experiment_sources_dir(),
-                                input_data.get_experiment_folder_name())
+        exp_root = dirname(samples_filepath)
 
         pipeline_ctx.update("exp_root", exp_root)
 
diff --git a/arelight/text/pipeline_entities_bert_ontonotes.py b/arelight/pipelines/items/entities_bert_ontonotes.py
similarity index 92%
rename from arelight/text/pipeline_entities_bert_ontonotes.py
rename to arelight/pipelines/items/entities_bert_ontonotes.py
index 3f133c2..e20b6f5 100644
--- a/arelight/text/pipeline_entities_bert_ontonotes.py
+++ b/arelight/pipelines/items/entities_bert_ontonotes.py
@@ -2,8 +2,9 @@
 from arekit.common.entities.base import Entity
 from arekit.common.news.objects_parser import SentenceObjectsParserPipelineItem
 from arekit.common.text.partitioning.terms import TermsPartitioning
-from arekit.processing.entities.obj_desc import NerObjectDescriptor
-from arelight.text.ner_ontonotes import BertOntonotesNER
+
+from arelight.ner.obj_desc import NerObjectDescriptor
+from arelight.ner.ontonotes import BertOntonotesNER
 
 
 class BertOntonotesNERPipelineItem(SentenceObjectsParserPipelineItem):
diff --git a/arelight/text/pipeline_entities_default.py b/arelight/pipelines/items/entities_default.py
similarity index 100%
rename from arelight/text/pipeline_entities_default.py
rename to arelight/pipelines/items/entities_default.py
diff --git a/arelight/pipelines/inference_bert.py b/arelight/pipelines/items/inference_bert.py
similarity index 88%
rename from arelight/pipelines/inference_bert.py
rename to arelight/pipelines/items/inference_bert.py
index 7afa17f..527ae8f 100644
--- a/arelight/pipelines/inference_bert.py
+++ b/arelight/pipelines/items/inference_bert.py
@@ -1,4 +1,4 @@
-from os.path import join
+from os.path import join, dirname
 
 from arekit.common.data.storages.base import BaseRowsStorage
 from arekit.common.experiment.data_type import DataType
@@ -7,21 +7,21 @@
 from arekit.common.pipeline.items.base import BasePipelineItem
 from arekit.contrib.networks.core.predict.base_writer import BasePredictWriter
 from arekit.contrib.networks.core.predict.provider import BasePredictProvider
+from arekit.contrib.utils.io_utils.samples import SamplesIO
 from deeppavlov.models.bert import bert_classifier
 from deeppavlov.models.preprocessors.bert_preprocessor import BertPreprocessor
 
-from arelight.exp.exp_io import InferIOUtils
-
 
 class BertInferencePipelineItem(BasePipelineItem):
 
-    def __init__(self, bert_config_file, model_checkpoint_path, vocab_filepath,
+    def __init__(self, bert_config_file, model_checkpoint_path, vocab_filepath, samples_io,
                  data_type, predict_writer, labels_scaler, max_seq_length, do_lowercase):
         assert(isinstance(predict_writer, BasePredictWriter))
         assert(isinstance(data_type, DataType))
         assert(isinstance(labels_scaler, BaseLabelScaler))
         assert(isinstance(do_lowercase, bool))
         assert(isinstance(max_seq_length, int))
+        assert(isinstance(samples_io, SamplesIO))
 
         # Model classifier.
         self.__model = bert_classifier.BertClassifierModel(
@@ -40,9 +40,9 @@ def __init__(self, bert_config_file, model_checkpoint_path, vocab_filepath,
         self.__data_type = data_type
         self.__labels_scaler = labels_scaler
         self.__predict_provider = BasePredictProvider()
+        self.__samples_io = samples_io
 
     def apply_core(self, input_data, pipeline_ctx):
-        assert(isinstance(input_data, InferIOUtils))
         assert(isinstance(pipeline_ctx, PipelineContext))
 
         def __iter_predict_result():
@@ -77,19 +77,19 @@ def __iter_predict_result():
                 for i, uint_label in enumerate(self.__model(batch_features)):
                     yield [row_ids[i], int(uint_label)]
 
+        # Fetch other required in furter information from input_data.
+        samples_filepath = self.__samples_io.create_target(
+            data_type=self.__data_type,
+            data_folding=pipeline_ctx.provide("data_folding"))
+
         # Setup predicted result writer.
         tgt = pipeline_ctx.provide_or_none("predict_fp")
         if tgt is None:
-            exp_root = join(input_data._get_experiment_sources_dir(),
-                            input_data.get_experiment_folder_name())
-            tgt = join(exp_root, "predict.tsv.gz")
+            tgt = join(dirname(samples_filepath), "predict.tsv.gz")
 
         # Setup target filepath.
         self.__writer.set_target(tgt)
 
-        # Fetch other required in furter information from input_data.
-        samples_filepath = input_data.create_samples_writer_target(self.__data_type)
-
         # Update for further pipeline items.
         pipeline_ctx.update("predict_fp", tgt)
 
@@ -100,3 +100,5 @@ def __iter_predict_result():
 
         with self.__writer:
             self.__writer.write(title=title, contents_it=contents_it)
+
+        return self.__samples_io
diff --git a/arelight/pipelines/inference_nn.py b/arelight/pipelines/items/inference_nn.py
similarity index 80%
rename from arelight/pipelines/inference_nn.py
rename to arelight/pipelines/items/inference_nn.py
index a3d70d3..a1fce91 100644
--- a/arelight/pipelines/inference_nn.py
+++ b/arelight/pipelines/items/inference_nn.py
@@ -1,9 +1,8 @@
-import os
-from os.path import join
+from os.path import join, dirname
 
 from arekit.common.data.row_ids.multiple import MultipleIDProvider
 from arekit.common.data.storages.base import BaseRowsStorage
-from arekit.common.data.views.samples import BaseSampleStorageView
+from arekit.common.data.views.samples import LinkedSamplesStorageView
 from arekit.common.experiment.data_type import DataType
 from arekit.common.pipeline.context import PipelineContext
 from arekit.common.pipeline.items.base import BasePipelineItem
@@ -18,19 +17,19 @@
 from arekit.contrib.networks.core.predict.base_writer import BasePredictWriter
 from arekit.contrib.networks.factory import create_network_and_network_config_funcs
 from arekit.contrib.networks.shapes import NetworkInputShapes
-from arekit.processing.languages.ru.pos_service import PartOfSpeechTypesService
-
-from arelight.exp.exp_io import InferIOUtils
+from arekit.contrib.utils.io_utils.samples import SamplesIO
+from arekit.contrib.utils.processing.languages.ru.pos_service import PartOfSpeechTypesService
 
 
 class TensorflowNetworkInferencePipelineItem(BasePipelineItem):
 
-    def __init__(self, model_name, bags_collection_type, model_input_type, predict_writer,
-                 data_type, bag_size, bags_per_minibatch, nn_io, labels_scaler, callbacks):
+    def __init__(self, model_name, bags_collection_type, model_input_type, predict_writer, samples_io,
+                 data_type, bag_size, bags_per_minibatch, nn_io, labels_scaler, callbacks, emb_io):
         assert(isinstance(callbacks, list))
         assert(isinstance(bag_size, int))
         assert(isinstance(predict_writer, BasePredictWriter))
         assert(isinstance(data_type, DataType))
+        assert(isinstance(samples_io, SamplesIO))
 
         # Create network an configuration.
         network_func, config_func = create_network_and_network_config_funcs(
@@ -61,25 +60,31 @@ def __init__(self, model_name, bags_collection_type, model_input_type, predict_w
         self.__writer = predict_writer
         self.__bags_collection_type = bags_collection_type
         self.__data_type = data_type
+        self.__samples_io = samples_io
+        self.__emb_io = emb_io
 
     def apply_core(self, input_data, pipeline_ctx):
-        assert(isinstance(input_data, InferIOUtils))
         assert(isinstance(pipeline_ctx, PipelineContext))
 
+        # Fetch other required in furter information from input_data.
+        samples_filepath = self.__samples_io.create_target(
+            data_type=self.__data_type,
+            data_folding=pipeline_ctx.provide("data_folding"))
+
         # Setup predicted result writer.
         tgt = pipeline_ctx.provide_or_none("predict_fp")
         if tgt is None:
-            exp_root = os.path.join(input_data._get_experiment_sources_dir(),
-                                    input_data.get_experiment_folder_name())
-            tgt = join(exp_root, "predict.tsv.gz")
+            tgt = join(dirname(samples_filepath), "predict.tsv.gz")
 
         # Update for further pipeline items.
         pipeline_ctx.update("predict_fp", tgt)
 
-        # Fetch other required in furter information from input_data.
-        samples_filepath = input_data.create_samples_writer_target(self.__data_type)
-        embedding = input_data.load_embedding()
-        vocab = input_data.load_vocab()
+        data_folding = pipeline_ctx.provide("data_folding")
+
+        # Fetch other required in further information from input_data.
+        samples_filepath = self.__samples_io.create_target(self.__data_type, data_folding=data_folding)
+        embedding = self.__emb_io.load_embedding(data_folding)
+        vocab = self.__emb_io.load_vocab(data_folding)
 
         # Setup config parameters.
         self.__config.set_term_embedding(embedding)
@@ -88,7 +93,7 @@ def apply_core(self, input_data, pipeline_ctx):
         inference_ctx.initialize(
             dtypes=[self.__data_type],
             bags_collection_type=self.__bags_collection_type,
-            create_samples_view_func=lambda data_type: BaseSampleStorageView(
+            create_samples_view_func=lambda data_type: LinkedSamplesStorageView(
                 storage=BaseRowsStorage.from_tsv(samples_filepath),
                 row_ids_provider=MultipleIDProvider()),
             has_model_predefined_state=True,
@@ -115,3 +120,5 @@ def apply_core(self, input_data, pipeline_ctx):
         self.__writer.set_target(tgt)
 
         model.predict(do_compile=True)
+
+        return self.__samples_io
diff --git a/arelight/pipelines/train_bert.py b/arelight/pipelines/items/train_bert.py
similarity index 95%
rename from arelight/pipelines/train_bert.py
rename to arelight/pipelines/items/train_bert.py
index 52be8f3..88a93f3 100644
--- a/arelight/pipelines/train_bert.py
+++ b/arelight/pipelines/items/train_bert.py
@@ -2,7 +2,7 @@
 from arekit.common.data.storages.base import BaseRowsStorage
 from arekit.common.pipeline.context import PipelineContext
 from arekit.common.pipeline.items.base import BasePipelineItem
-from arekit.common.synonyms import SynonymsCollection
+from arekit.common.synonyms.base import SynonymsCollection
 from deeppavlov.models.bert import bert_classifier
 from deeppavlov.models.preprocessors.bert_preprocessor import BertPreprocessor
 from tqdm import tqdm
@@ -11,7 +11,8 @@
 class BertFinetunePipelineItem(BasePipelineItem):
 
     def __init__(self, bert_config_file, model_checkpoint_path, do_lowercase,
-                 learning_rate, vocab_filepath, max_seq_length, save_path):
+                 learning_rate, vocab_filepath, max_seq_length, save_path,
+                 labels_count=3):
         assert(isinstance(bert_config_file, str))
         assert(isinstance(model_checkpoint_path, str))
 
@@ -20,7 +21,7 @@ def __init__(self, bert_config_file, model_checkpoint_path, do_lowercase,
             bert_config_file=bert_config_file,
             load_path=model_checkpoint_path,
             keep_prob=0.1,
-            n_classes=3,
+            n_classes=labels_count,
             save_path=save_path,
             learning_rate=learning_rate)
 
diff --git a/arelight/pipelines/utils.py b/arelight/pipelines/items/utils.py
similarity index 100%
rename from arelight/pipelines/utils.py
rename to arelight/pipelines/items/utils.py
diff --git a/arelight/pipelines/serialize_bert.py b/arelight/pipelines/serialize_bert.py
deleted file mode 100644
index 29144cc..0000000
--- a/arelight/pipelines/serialize_bert.py
+++ /dev/null
@@ -1,100 +0,0 @@
-from arekit.common.entities.str_fmt import StringEntitiesFormatter
-from arekit.common.experiment.api.base import BaseExperiment
-from arekit.common.experiment.engine import ExperimentEngine
-from arekit.common.experiment.name_provider import ExperimentNameProvider
-from arekit.common.folding.base import BaseDataFolding
-from arekit.common.labels.base import NoLabel
-from arekit.common.labels.scaler.single import SingleLabelScaler
-from arekit.common.labels.str_fmt import StringLabelsFormatter
-from arekit.common.news.entities_grouping import EntitiesGroupingPipelineItem
-from arekit.common.pipeline.items.base import BasePipelineItem
-from arekit.common.synonyms import SynonymsCollection
-from arekit.common.text.parser import BaseTextParser
-from arekit.contrib.bert.handlers.serializer import BertExperimentInputSerializerIterationHandler
-from arekit.contrib.bert.samplers.types import BertSampleProviderTypes
-from arekit.processing.text.pipeline_terms_splitter import TermsSplitterParser
-
-from arelight.exp.doc_ops import CustomDocOperations
-from arelight.exp.exp_io import InferIOUtils
-from arelight.exp.opin_ops import CustomOpinionOperations
-from arelight.network.bert.ctx import BertSerializationContext
-from arelight.pipelines.utils import input_to_docs
-
-
-class BertTextsSerializationPipelineItem(BasePipelineItem):
-
-    def __init__(self, terms_per_context, entities_parser, synonyms, opin_annot, name_provider,
-                 entity_fmt, text_b_type, data_folding, output_dir):
-        assert(isinstance(entities_parser, BasePipelineItem))
-        assert(isinstance(entity_fmt, StringEntitiesFormatter))
-        assert(isinstance(synonyms, SynonymsCollection))
-        assert(isinstance(terms_per_context, int))
-        assert(isinstance(data_folding, BaseDataFolding))
-        assert(isinstance(text_b_type, BertSampleProviderTypes))
-        assert(isinstance(name_provider, ExperimentNameProvider))
-        assert(isinstance(output_dir, str))
-
-        # Label provider setup.
-        labels_fmt = StringLabelsFormatter(stol={"neu": NoLabel})
-
-        self.__exp_ctx = BertSerializationContext(
-            label_scaler=SingleLabelScaler(NoLabel()),
-            annotator=opin_annot,
-            terms_per_context=terms_per_context,
-            str_entity_formatter=entity_fmt,
-            name_provider=name_provider,
-            data_folding=data_folding)
-
-        self.__exp_io = InferIOUtils(exp_ctx=self.__exp_ctx, output_dir=output_dir)
-
-        text_parser = BaseTextParser(pipeline=[
-            TermsSplitterParser(),
-            entities_parser,
-            EntitiesGroupingPipelineItem(lambda value: self.get_synonym_group_index(synonyms, value))])
-
-        self.__doc_ops = CustomDocOperations(exp_ctx=self.__exp_ctx,
-                                             text_parser=text_parser)
-
-        self.__opin_ops = CustomOpinionOperations(
-            labels_formatter=labels_fmt,
-            exp_io=self.__exp_io,
-            synonyms=synonyms,
-            neutral_labels_fmt=labels_fmt)
-
-        exp = BaseExperiment(
-            exp_io=self.__exp_io,
-            exp_ctx=self.__exp_ctx,
-            doc_ops=self.__doc_ops,
-            opin_ops=self.__opin_ops)
-
-        self.__handler = BertExperimentInputSerializerIterationHandler(
-            exp_io=self.__exp_io,
-            exp_ctx=self.__exp_ctx,
-            doc_ops=self.__doc_ops,
-            opin_ops=exp.OpinionOperations,
-            sample_labels_fmt=labels_fmt,
-            annot_labels_fmt=labels_fmt,
-            sample_provider_type=text_b_type,
-            entity_formatter=self.__exp_ctx.StringEntityFormatter,
-            value_to_group_id_func=synonyms.get_synonym_group_index,
-            balance_train_samples=True)
-
-    @staticmethod
-    def get_synonym_group_index(synonyms, value):
-        assert(isinstance(synonyms, SynonymsCollection))
-        if not synonyms.contains_synonym_value(value):
-            synonyms.add_synonym_value(value)
-        return synonyms.get_synonym_group_index(value)
-
-    def apply_core(self, input_data, pipeline_ctx):
-        assert(isinstance(input_data, list))
-
-        docs = input_to_docs(input_data)
-
-        # Setup document.
-        self.__doc_ops.set_docs(docs)
-
-        engine = ExperimentEngine(self.__exp_ctx.DataFolding)
-        engine.run([self.__handler])
-
-        return self.__exp_io
diff --git a/arelight/pipelines/serialize_nn.py b/arelight/pipelines/serialize_nn.py
deleted file mode 100644
index 795b05b..0000000
--- a/arelight/pipelines/serialize_nn.py
+++ /dev/null
@@ -1,123 +0,0 @@
-from arekit.common.entities.str_fmt import StringEntitiesFormatter
-from arekit.common.experiment.api.base import BaseExperiment
-from arekit.common.experiment.name_provider import ExperimentNameProvider
-from arekit.common.folding.base import BaseDataFolding
-from arekit.common.labels.base import NoLabel
-from arekit.common.labels.scaler.single import SingleLabelScaler
-from arekit.common.labels.str_fmt import StringLabelsFormatter
-from arekit.common.news.entities_grouping import EntitiesGroupingPipelineItem
-from arekit.common.pipeline.items.base import BasePipelineItem
-from arekit.common.synonyms import SynonymsCollection
-from arekit.common.text.parser import BaseTextParser
-from arekit.common.text.stemmer import Stemmer
-from arekit.contrib.networks.core.input.helper import NetworkInputHelper
-from arekit.contrib.source.rusentiframes.collection import RuSentiFramesCollection
-from arekit.processing.lemmatization.mystem import MystemWrapper
-from arekit.processing.pos.mystem_wrap import POSMystemWrapper
-from arekit.processing.text.pipeline_frames import FrameVariantsParser
-from arekit.processing.text.pipeline_frames_lemmatized import LemmasBasedFrameVariantsParser
-from arekit.processing.text.pipeline_frames_negation import FrameVariantsSentimentNegation
-from arekit.processing.text.pipeline_terms_splitter import TermsSplitterParser
-from arekit.processing.text.pipeline_tokenizer import DefaultTextTokenizer
-
-from arelight.exp.doc_ops import CustomDocOperations
-from arelight.exp.exp_io import InferIOUtils
-from arelight.exp.opin_ops import CustomOpinionOperations
-from arelight.network.nn.common import create_and_fill_variant_collection
-from arelight.network.nn.ctx import NetworkSerializationContext
-from arelight.network.nn.embedding import RusvectoresEmbedding
-from arelight.pipelines.utils import input_to_docs
-
-
-class NetworkTextsSerializationPipelineItem(BasePipelineItem):
-
-    def __init__(self, terms_per_context, entities_parser, synonyms, opin_annot, name_provider,
-                 embedding_path, frames_collection, entity_fmt, stemmer, data_folding, output_dir):
-        assert(isinstance(frames_collection, RuSentiFramesCollection))
-        assert(isinstance(entities_parser, BasePipelineItem))
-        assert(isinstance(entity_fmt, StringEntitiesFormatter))
-        assert(isinstance(synonyms, SynonymsCollection))
-        assert(isinstance(terms_per_context, int))
-        assert(isinstance(embedding_path, str))
-        assert(isinstance(stemmer, Stemmer))
-        assert(isinstance(data_folding, BaseDataFolding))
-        assert(isinstance(name_provider, ExperimentNameProvider))
-        assert(isinstance(output_dir, str))
-
-        # Initalize embedding.
-        embedding = RusvectoresEmbedding.from_word2vec_format(filepath=embedding_path, binary=True)
-        embedding.set_stemmer(stemmer)
-
-        # Initialize synonyms collection.
-        self.__synonyms = synonyms
-        pos_tagger = POSMystemWrapper(MystemWrapper().MystemInstance)
-
-        # Label provider setup.
-        self.__labels_fmt = StringLabelsFormatter(stol={"neu": NoLabel})
-
-        # Initialize text parser with the related dependencies.
-        frame_variants_collection = create_and_fill_variant_collection(frames_collection)
-        self.__text_parser = BaseTextParser(pipeline=[
-            TermsSplitterParser(),
-            entities_parser,
-            EntitiesGroupingPipelineItem(lambda value: self.get_synonym_group_index(self.__synonyms, value)),
-            DefaultTextTokenizer(keep_tokens=True),
-            FrameVariantsParser(frame_variants=frame_variants_collection),
-            LemmasBasedFrameVariantsParser(save_lemmas=False,
-                                           stemmer=stemmer,
-                                           frame_variants=frame_variants_collection),
-            FrameVariantsSentimentNegation()])
-
-        # initialize expriment related data.
-        self.__exp_ctx = NetworkSerializationContext(
-            labels_scaler=SingleLabelScaler(NoLabel()),
-            embedding=embedding,
-            annotator=opin_annot,
-            terms_per_context=terms_per_context,
-            str_entity_formatter=entity_fmt,
-            pos_tagger=pos_tagger,
-            name_provider=name_provider,
-            frames_collection=frames_collection,
-            frame_variant_collection=frame_variants_collection,
-            data_folding=data_folding)
-
-        self.__exp_io = InferIOUtils(exp_ctx=self.__exp_ctx, output_dir=output_dir)
-
-        self.__doc_ops = CustomDocOperations(exp_ctx=self.__exp_ctx,
-                                             text_parser=self.__text_parser)
-
-        self.__opin_ops = CustomOpinionOperations(
-            labels_formatter=self.__labels_fmt,
-            exp_io=self.__exp_io,
-            synonyms=synonyms,
-            neutral_labels_fmt=self.__labels_fmt)
-
-        self.__exp = BaseExperiment(exp_io=self.__exp_io,
-                                    exp_ctx=self.__exp_ctx,
-                                    doc_ops=self.__doc_ops,
-                                    opin_ops=self.__opin_ops)
-
-    @staticmethod
-    def get_synonym_group_index(synonyms, value):
-        assert(isinstance(synonyms, SynonymsCollection))
-        if not synonyms.contains_synonym_value(value):
-            synonyms.add_synonym_value(value)
-        return synonyms.get_synonym_group_index(value)
-
-    def apply_core(self, input_data, pipeline_ctx):
-        assert(isinstance(input_data, list))
-
-        docs = input_to_docs(input_data)
-
-        # Setup document.
-        self.__doc_ops.set_docs(docs)
-
-        NetworkInputHelper.prepare(exp_ctx=self.__exp.ExperimentContext,
-                                   exp_io=self.__exp.ExperimentIO,
-                                   doc_ops=self.__exp.DocumentOperations,
-                                   opin_ops=self.__exp.OpinionOperations,
-                                   terms_per_context=self.__exp_ctx.TermsPerContext,
-                                   balance=False,
-                                   value_to_group_id_func=self.__synonyms.get_synonym_group_index)
-
-        return self.__exp.ExperimentIO
diff --git a/examples/rusentrel/__init__.py b/arelight/samplers/__init__.py
similarity index 100%
rename from examples/rusentrel/__init__.py
rename to arelight/samplers/__init__.py
diff --git a/arelight/samplers/bert.py b/arelight/samplers/bert.py
new file mode 100644
index 0000000..344dbd5
--- /dev/null
+++ b/arelight/samplers/bert.py
@@ -0,0 +1,37 @@
+from arekit.common.data.input.providers.label.multiple import MultipleLabelProvider
+from arekit.common.data.input.providers.rows.samples import BaseSampleRowProvider
+from arekit.common.data.input.providers.text.single import BaseSingleTextProvider
+from arekit.common.entities.str_fmt import StringEntitiesFormatter
+from arekit.common.labels.scaler.base import BaseLabelScaler
+from arekit.common.labels.str_fmt import StringLabelsFormatter
+from arekit.contrib.bert.input.providers.text_pair import PairTextProvider
+from arekit.contrib.bert.terms.mapper import BertDefaultStringTextTermsMapper
+from arekit.contrib.utils.bert.text_b_rus import BertTextBTemplates
+
+from arelight.samplers.types import BertSampleProviderTypes
+
+
+def create_bert_sample_provider(provider_type, label_scaler, text_b_labels_fmt, entity_formatter):
+    """ This is a factory method, which allows to instantiate any of the
+        supported bert_sample_encoders
+    """
+    assert(isinstance(provider_type, BertSampleProviderTypes))
+    assert(isinstance(entity_formatter, StringEntitiesFormatter))
+    assert(isinstance(text_b_labels_fmt, StringLabelsFormatter))
+    assert(isinstance(label_scaler, BaseLabelScaler))
+
+    text_terms_mapper = BertDefaultStringTextTermsMapper(entity_formatter)
+
+    text_b_template = None
+    if provider_type == BertSampleProviderTypes.NLI_M:
+        text_b_template = BertTextBTemplates.NLI.value
+    if provider_type == BertSampleProviderTypes.QA_M:
+        text_b_template = BertTextBTemplates.QA.value
+
+    text_provider = BaseSingleTextProvider(text_terms_mapper=text_terms_mapper) \
+        if text_b_labels_fmt is None else PairTextProvider(text_b_template=text_b_template,
+                                                           text_b_labels_fmt=text_b_labels_fmt,
+                                                           text_terms_mapper=text_terms_mapper)
+
+    return BaseSampleRowProvider(label_provider=MultipleLabelProvider(label_scaler),
+                                 text_provider=text_provider)
diff --git a/arelight/samplers/types.py b/arelight/samplers/types.py
new file mode 100644
index 0000000..c34c16f
--- /dev/null
+++ b/arelight/samplers/types.py
@@ -0,0 +1,30 @@
+from enum import Enum
+
+from examples.utils import EnumConversionService
+
+
+class BertSampleProviderTypes(Enum):
+    """
+    Supported format types.
+    """
+
+    """
+    Default formatter
+    """
+    CLASSIF_M = 0
+
+    """
+    Natural Language Inference samplers
+    paper: https://www.aclweb.org/anthology/N19-1035.pdf
+    """
+    QA_M = 1
+    NLI_M = 2
+
+
+class SampleFormattersService(EnumConversionService):
+
+    _data = {
+        'c_m': BertSampleProviderTypes.CLASSIF_M,
+        "qa_m": BertSampleProviderTypes.QA_M,
+        'nli_m': BertSampleProviderTypes.NLI_M,
+    }
\ No newline at end of file
diff --git a/dependencies.txt b/dependencies.txt
index d69faac..3348d77 100644
--- a/dependencies.txt
+++ b/dependencies.txt
@@ -1,4 +1,3 @@
-gensim==3.2.0
 deeppavlov==0.11.0
 rusenttokenize
 # DeepPavlov bert-dp dependencies:
diff --git a/download.py b/download.py
index 194d928..087d4e8 100644
--- a/download.py
+++ b/download.py
@@ -1,6 +1,8 @@
 import os
 import tarfile
-from arekit.contrib.source import utils
+
+from arekit.common import utils
+
 from examples.args import const
 
 
@@ -8,7 +10,6 @@ def download_examples_data():
     root_dir = utils.get_default_download_dir()
 
     data = {
-        const.EMBEDDING_FILEPATH: "http://rusvectores.org/static/models/rusvectores2/news_mystem_skipgram_1000_20_2015.bin.gz",
         const.SYNONYMS_FILEPATH: "https://raw.githubusercontent.com/nicolay-r/RuSentRel/v1.1/synonyms.txt",
         # PCNN: pretrained model dir.
         const.PCNN_DEFAULT_MODEL_TAR: "https://www.dropbox.com/s/ceqy69vj59te534/fx_ctx_pcnn.tar.gz?dl=1",
diff --git a/examples/args/common.py b/examples/args/common.py
index 24459ee..6c83c6b 100644
--- a/examples/args/common.py
+++ b/examples/args/common.py
@@ -1,15 +1,17 @@
-from arekit.contrib.bert.samplers.types import SampleFormattersService
-from arekit.contrib.experiment_rusentrel.entities.types import EntityFormattersService
-from arekit.contrib.experiment_rusentrel.labels.formatters.rusentiframes import ExperimentRuSentiFramesLabelsFormatter
 from arekit.contrib.networks.enum_name_types import ModelNamesService
 from arekit.contrib.source.rusentiframes.collection import RuSentiFramesCollection
+from arekit.contrib.source.rusentiframes.labels_fmt import RuSentiFramesLabelsFormatter, \
+    RuSentiFramesEffectLabelsFormatter
 from arekit.contrib.source.rusentiframes.types import RuSentiFramesVersionsService, RuSentiFramesVersions
-from arekit.processing.lemmatization.mystem import MystemWrapper
-from arelight.text.pipeline_entities_bert_ontonotes import BertOntonotesNERPipelineItem
+from arekit.contrib.utils.processing.lemmatization.mystem import MystemWrapper
 
-from arelight.text.pipeline_entities_default import TextEntitiesParser
+from arelight.pipelines.demo.labels.base import NegativeLabel, PositiveLabel
+from arelight.pipelines.items.entities_bert_ontonotes import BertOntonotesNERPipelineItem
+from arelight.pipelines.items.entities_default import TextEntitiesParser
+from arelight.samplers.types import SampleFormattersService
 
 from examples.args.base import BaseArg
+from examples.entities.types import EntityFormattersService
 
 
 class InputTextArg(BaseArg):
@@ -35,7 +37,10 @@ def read_argument(args):
         if args.frames == "ruattitudes-20":
             return RuSentiFramesCollection.read_collection(
                 version=RuSentiFramesVersions.V20,
-                labels_fmt=ExperimentRuSentiFramesLabelsFormatter())
+                labels_fmt=RuSentiFramesLabelsFormatter(
+                    pos_label_type=PositiveLabel, neg_label_type=NegativeLabel),
+                effect_labels_fmt=RuSentiFramesEffectLabelsFormatter(
+                    pos_label_type=PositiveLabel, neg_label_type=NegativeLabel))
 
     @staticmethod
     def add_argument(parser, default="ruattitudes-20"):
diff --git a/examples/args/const.py b/examples/args/const.py
index c9bdcac..40a2ecf 100644
--- a/examples/args/const.py
+++ b/examples/args/const.py
@@ -10,7 +10,6 @@
 
 DATA_DIR = join(current_dir, "../../data")
 DEFAULT_TEXT_FILEPATH = join(DATA_DIR, "texts-inosmi-rus/e1.txt")
-EMBEDDING_FILEPATH = join(DATA_DIR, "news_mystem_skipgram_1000_20_2015.bin.gz")
 SYNONYMS_FILEPATH = join(DATA_DIR, "synonyms.txt")
 
 # Common model dir.
diff --git a/examples/demo/wui_bert.py b/examples/demo/wui_bert.py
index 40c332e..55bd0e6 100644
--- a/examples/demo/wui_bert.py
+++ b/examples/demo/wui_bert.py
@@ -7,7 +7,22 @@
 import sys
 from os.path import join, basename
 
-from arelight.demo.infer_bert_rus import demo_infer_texts_bert_pipeline
+from arekit.common.experiment.data_type import DataType
+from arekit.common.folding.nofold import NoFolding
+from arekit.common.news.entities_grouping import EntitiesGroupingPipelineItem
+from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
+from arekit.common.text.parser import BaseTextParser
+from arekit.contrib.utils.entities.formatters.str_simple_sharp_prefixed_fmt import SharpPrefixedEntitiesSimpleFormatter
+from arekit.contrib.utils.pipelines.items.text.terms_splitter import TermsSplitterParser
+from arekit.contrib.utils.processing.lemmatization.mystem import MystemWrapper
+
+from arelight.doc_ops import InMemoryDocOperations
+from arelight.pipelines.annot_nolabel import create_neutral_annotation_pipeline
+from arelight.pipelines.demo.infer_bert_rus import demo_infer_texts_bert_pipeline
+from arelight.pipelines.demo.labels.scalers import ThreeLabelScaler
+from arelight.pipelines.demo.utils import read_synonyms_collection
+from arelight.pipelines.items.entities_bert_ontonotes import BertOntonotesNERPipelineItem
+from arelight.pipelines.items.utils import input_to_docs
 
 bratUrl = '/brat/'
 
@@ -56,15 +71,42 @@ def prepare_template(data, text, bratUrl):
 state_name = "ra-20-srubert-large-neut-nli-pretrained-3l"
 finetuned_state_name = "ra-20-srubert-large-neut-nli-pretrained-3l-finetuned"
 
-ppl = demo_infer_texts_bert_pipeline(
+demo_pipeline = demo_infer_texts_bert_pipeline(
     texts_count=1,
     output_dir=".",
+    entity_fmt=SharpPrefixedEntitiesSimpleFormatter(),
     bert_config_path=join(model_dir, state_name, "bert_config.json"),
     bert_vocab_path=join(model_dir, state_name, "vocab.txt"),
     bert_finetuned_ckpt_path=join(model_dir, finetuned_state_name, state_name),
-    synonyms_filepath="/arelight/data/synonyms.txt")
-
-brat_json = ppl.run([text.strip()])
+    labels_scaler=ThreeLabelScaler())
+
+synonyms = read_synonyms_collection(synonyms_filepath="/arelight/data/synonyms.txt",
+                                    stemmer=MystemWrapper())
+
+text_parser = BaseTextParser(pipeline=[
+    TermsSplitterParser(),
+    BertOntonotesNERPipelineItem(lambda s_obj: s_obj.ObjectType in ["ORG", "PERSON", "LOC", "GPE"]),
+    EntitiesGroupingPipelineItem(
+        lambda value: SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
+            synonyms=synonyms, value=value))
+])
+
+# Declare a single document with `0` id and contents.
+single_doc = [text.strip()]
+doc_ops = InMemoryDocOperations(docs=input_to_docs(single_doc))
+
+data_pipeline = create_neutral_annotation_pipeline(synonyms=synonyms,
+                                                   terms_per_context=50,
+                                                   dist_in_terms_bound=50,
+                                                   doc_ops=doc_ops,
+                                                   text_parser=text_parser)
+
+no_folding = NoFolding(doc_ids_to_fold=[0], supported_data_types=[DataType.Test])
+
+brat_json = demo_pipeline.run(None, {
+    "data_type_pipelines": {DataType.Test: data_pipeline},
+    "data_folding": no_folding
+})
 
 template = prepare_template(brat_json, text, bratUrl)
 cgi_output(template)
diff --git a/examples/demo/wui_nn.py b/examples/demo/wui_nn.py
index b247cd5..a3a0eaa 100644
--- a/examples/demo/wui_nn.py
+++ b/examples/demo/wui_nn.py
@@ -7,14 +7,34 @@
 import sys
 from os.path import join, basename
 
-from arekit.contrib.experiment_rusentrel.labels.formatters.rusentiframes import ExperimentRuSentiFramesLabelsFormatter
+from arekit.common.experiment.data_type import DataType
+from arekit.common.folding.nofold import NoFolding
+from arekit.common.news.entities_grouping import EntitiesGroupingPipelineItem
+from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
+from arekit.common.text.parser import BaseTextParser
 from arekit.contrib.networks.enum_input_types import ModelInputType
 from arekit.contrib.networks.enum_name_types import ModelNames
 from arekit.contrib.source.rusentiframes.collection import RuSentiFramesCollection
+from arekit.contrib.source.rusentiframes.labels_fmt import RuSentiFramesLabelsFormatter, \
+    RuSentiFramesEffectLabelsFormatter
 from arekit.contrib.source.rusentiframes.types import RuSentiFramesVersions
-
-from arelight.demo.infer_nn_rus import demo_infer_texts_tensorflow_nn_pipeline
-
+from arekit.contrib.utils.entities.formatters.str_simple_fmt import StringEntitiesSimpleFormatter
+from arekit.contrib.utils.pipelines.items.text.frames import FrameVariantsParser
+from arekit.contrib.utils.pipelines.items.text.frames_lemmatized import LemmasBasedFrameVariantsParser
+from arekit.contrib.utils.pipelines.items.text.frames_negation import FrameVariantsSentimentNegation
+from arekit.contrib.utils.pipelines.items.text.terms_splitter import TermsSplitterParser
+from arekit.contrib.utils.pipelines.items.text.tokenizer import DefaultTextTokenizer
+from arekit.contrib.utils.processing.lemmatization.mystem import MystemWrapper
+
+from arelight.doc_ops import InMemoryDocOperations
+from arelight.network.nn.common import create_and_fill_variant_collection
+from arelight.pipelines.annot_nolabel import create_neutral_annotation_pipeline
+from arelight.pipelines.demo.infer_nn_rus import demo_infer_texts_tensorflow_nn_pipeline
+from arelight.pipelines.demo.labels.base import NegativeLabel, PositiveLabel
+from arelight.pipelines.demo.utils import read_synonyms_collection
+from arelight.pipelines.items.backend_brat_html import BratHtmlEmbeddingPipelineItem
+from arelight.pipelines.items.entities_bert_ontonotes import BertOntonotesNERPipelineItem
+from arelight.pipelines.items.utils import input_to_docs
 
 bratUrl = '/brat/'
 
@@ -65,23 +85,57 @@ def prepare_template(data, text, bratUrl, model_name):
 
 frames_collection = RuSentiFramesCollection.read_collection(
     version=RuSentiFramesVersions.V20,
-    labels_fmt=ExperimentRuSentiFramesLabelsFormatter())
+    labels_fmt=RuSentiFramesLabelsFormatter(
+        pos_label_type=PositiveLabel, neg_label_type=NegativeLabel),
+    effect_labels_fmt=RuSentiFramesEffectLabelsFormatter(
+        pos_label_type=PositiveLabel, neg_label_type=NegativeLabel))
 
-ppl = demo_infer_texts_tensorflow_nn_pipeline(
+demo_pipeline = demo_infer_texts_tensorflow_nn_pipeline(
     texts_count=1,
     output_dir=".",
     model_name=model_name,
     model_input_type=ModelInputType.SingleInstance,
-    synonyms_filepath=join(data_dir, "synonyms.txt"),
+    entity_fmt=StringEntitiesSimpleFormatter(),
     model_load_dir=join(data_dir, "models"),
-    embedding_filepath=join(data_dir, "news_mystem_skipgram_1000_20_2015.bin.gz"),
     frames_collection=frames_collection)
 
-brat_json = ppl.run([text.strip()])
-
-template = prepare_template(data=brat_json,
-                            text=text,
-                            bratUrl=bratUrl,
-                            model_name=model_name)
-
+stemmer = MystemWrapper()
+synonyms = read_synonyms_collection(synonyms_filepath="/arelight/data/synonyms.txt", stemmer=stemmer)
+
+demo_pipeline.append(BratHtmlEmbeddingPipelineItem(brat_url="http://localhost:8001/"))
+
+# Declare a single document with `0` id and contents.
+single_doc = [text.strip()]
+doc_ops = InMemoryDocOperations(docs=input_to_docs(single_doc))
+
+# Initialize text parser with the related dependencies.
+frame_variants_collection = create_and_fill_variant_collection(frames_collection)
+text_parser = BaseTextParser(pipeline=[
+    TermsSplitterParser(),
+    BertOntonotesNERPipelineItem(lambda s_obj: s_obj.ObjectType in ["ORG", "PERSON", "LOC", "GPE"]),
+    EntitiesGroupingPipelineItem(
+        lambda value: SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
+            synonyms, value)),
+    DefaultTextTokenizer(keep_tokens=True),
+    FrameVariantsParser(frame_variants=frame_variants_collection),
+    LemmasBasedFrameVariantsParser(save_lemmas=False,
+                                   stemmer=stemmer,
+                                   frame_variants=frame_variants_collection),
+    FrameVariantsSentimentNegation()])
+
+data_pipeline = create_neutral_annotation_pipeline(synonyms=synonyms,
+                                                   dist_in_terms_bound=50,
+                                                   terms_per_context=50,
+                                                   doc_ops=doc_ops,
+                                                   text_parser=text_parser,
+                                                   dist_in_sentences=0)
+
+no_folding = NoFolding(doc_ids_to_fold=[0], supported_data_types=[DataType.Test])
+
+brat_json = demo_pipeline.run([text.strip()], {
+    "data_type_pipelines": {DataType.Test: data_pipeline},
+    "data_folding": no_folding
+})
+
+template = prepare_template(data=brat_json, text=text, bratUrl=bratUrl, model_name=model_name)
 cgi_output(template)
diff --git a/examples/rusentrel/configs/__init__.py b/examples/entities/__init__.py
similarity index 100%
rename from examples/rusentrel/configs/__init__.py
rename to examples/entities/__init__.py
diff --git a/examples/entities/factory.py b/examples/entities/factory.py
new file mode 100644
index 0000000..394f0c5
--- /dev/null
+++ b/examples/entities/factory.py
@@ -0,0 +1,26 @@
+from arekit.contrib.utils.entities.formatters.str_rus_cased_fmt import RussianEntitiesCasedFormatter
+from arekit.contrib.utils.entities.formatters.str_rus_nocased_fmt import RussianEntitiesFormatter
+from arekit.contrib.utils.entities.formatters.str_simple_fmt import StringEntitiesSimpleFormatter
+from arekit.contrib.utils.entities.formatters.str_simple_sharp_prefixed_fmt import SharpPrefixedEntitiesSimpleFormatter
+from arekit.contrib.utils.entities.formatters.str_simple_uppercase_fmt import SimpleUppercasedEntityFormatter
+
+from examples.entities.types import EntityFormatterTypes
+
+
+def create_entity_formatter(fmt_type, create_russian_pos_tagger_func=None):
+    """ Factory method for entity formatters, applicable in bert.
+    """
+    assert(isinstance(fmt_type, EntityFormatterTypes))
+    assert(callable(create_russian_pos_tagger_func) or create_russian_pos_tagger_func is None)
+
+    if fmt_type == EntityFormatterTypes.RussianCased:
+        return RussianEntitiesCasedFormatter(create_russian_pos_tagger_func())
+    elif fmt_type == EntityFormatterTypes.HiddenBertStyled:
+        return SharpPrefixedEntitiesSimpleFormatter()
+    elif fmt_type == EntityFormatterTypes.HiddenSimpleRus:
+        return RussianEntitiesFormatter()
+    elif fmt_type == EntityFormatterTypes.HiddenSimpleEng:
+        return StringEntitiesSimpleFormatter()
+    elif fmt_type == EntityFormatterTypes.HiddenSimpleUppercase:
+        return SimpleUppercasedEntityFormatter()
+
diff --git a/examples/entities/types.py b/examples/entities/types.py
new file mode 100644
index 0000000..f6c87dc
--- /dev/null
+++ b/examples/entities/types.py
@@ -0,0 +1,23 @@
+from enum import Enum
+
+from examples.utils import EnumConversionService
+
+
+class EntityFormatterTypes(Enum):
+
+    RussianCased = 1
+    HiddenSimpleRus = 2
+    HiddenSimpleEng = 3
+    HiddenSimpleUppercase = 4
+    HiddenBertStyled = 5
+
+
+class EntityFormattersService(EnumConversionService):
+
+    _data = {
+        "rus-cased-fmt": EntityFormatterTypes.RussianCased,
+        'hidden-simple-eng': EntityFormatterTypes.HiddenSimpleEng,
+        'hidden-simple-rus': EntityFormatterTypes.HiddenSimpleRus,
+        'hidden-simple-rus-uppercase': EntityFormatterTypes.HiddenSimpleUppercase,
+        'hidden-bert-styled': EntityFormatterTypes.HiddenBertStyled
+    }
diff --git a/examples/infer_texts_bert.py b/examples/infer_bert.py
similarity index 52%
rename from examples/infer_texts_bert.py
rename to examples/infer_bert.py
index 720d43c..d8af32e 100644
--- a/examples/infer_texts_bert.py
+++ b/examples/infer_bert.py
@@ -1,14 +1,25 @@
 import argparse
 from os.path import join
 
+from arekit.common.experiment.data_type import DataType
+from arekit.common.folding.nofold import NoFolding
+from arekit.common.news.entities_grouping import EntitiesGroupingPipelineItem
+from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
+from arekit.common.text.parser import BaseTextParser
+from arekit.contrib.utils.pipelines.items.text.terms_splitter import TermsSplitterParser
 
-from arelight.demo.infer_bert_rus import demo_infer_texts_bert_pipeline
-from arelight.pipelines.backend_brat_html import BratHtmlEmbeddingPipelineItem
+from arelight.doc_ops import InMemoryDocOperations
+from arelight.pipelines.annot_nolabel import create_neutral_annotation_pipeline
+from arelight.pipelines.demo.infer_bert_rus import demo_infer_texts_bert_pipeline
+from arelight.pipelines.items.backend_brat_html import BratHtmlEmbeddingPipelineItem
+from arelight.pipelines.items.utils import input_to_docs
 
 from examples.args import common
 from examples.args import train
 from examples.args import const
-from examples.utils import create_labels_scaler
+from examples.entities.factory import create_entity_formatter
+from examples.entities.types import EntityFormatterTypes
+from examples.utils import create_labels_scaler, read_synonyms_collection
 
 if __name__ == '__main__':
 
@@ -23,6 +34,7 @@
     common.TokensPerContextArg.add_argument(parser, default=128)
     common.EntityFormatterTypesArg.add_argument(parser, default="hidden-bert-styled")
     common.PredictOutputFilepathArg.add_argument(parser, default=None)
+    common.EntitiesParserArg.add_argument(parser, default="bert-ontonotes")
     common.BertCheckpointFilepathArg.add_argument(parser, default=const.BERT_FINETUNED_CKPT_PATH)
     common.BertConfigFilepathArg.add_argument(parser, default=const.BERT_CONFIG_PATH)
     common.BertVocabFilepathArg.add_argument(parser, default=const.BERT_VOCAB_PATH)
@@ -35,29 +47,52 @@
     # Reading text-related parameters.
     texts_from_files = common.FromFilesArg.read_argument(args)
     text_from_arg = common.InputTextArg.read_argument(args)
+    entities_parser = common.EntitiesParserArg.read_argument(args)
+    terms_per_context = common.TermsPerContextArg.read_argument(args)
     actual_content = text_from_arg if text_from_arg is not None else texts_from_files
 
-    ppl = demo_infer_texts_bert_pipeline(
+    pipeline = demo_infer_texts_bert_pipeline(
         texts_count=len(texts_from_files),
         output_dir=const.OUTPUT_DIR,
+        entity_fmt=create_entity_formatter(EntityFormatterTypes.HiddenBertStyled),
         labels_scaler=create_labels_scaler(common.LabelsCountArg.read_argument(args)),
-        synonyms_filepath=common.SynonymsCollectionFilepathArg.read_argument(args),
         bert_config_path=common.BertConfigFilepathArg.read_argument(args),
         bert_vocab_path=common.BertVocabFilepathArg.read_argument(args),
         bert_finetuned_ckpt_path=common.BertCheckpointFilepathArg.read_argument(args),
-        terms_per_context=common.TermsPerContextArg.read_argument(args),
         do_lowercase=train.DoLowercaseArg.read_argument(args),
         max_seq_length=common.TokensPerContextArg.read_argument(args)
     )
 
-    ppl.append(
+    synonyms = read_synonyms_collection(filepath=common.SynonymsCollectionFilepathArg.read_argument(args))
+
+    text_parser = BaseTextParser(pipeline=[
+        TermsSplitterParser(),
+        entities_parser,
+        EntitiesGroupingPipelineItem(
+            lambda value: SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
+                synonyms=synonyms, value=value))
+    ])
+
+    data_pipeline = create_neutral_annotation_pipeline(
+        synonyms=synonyms,
+        dist_in_terms_bound=terms_per_context,
+        doc_ops=InMemoryDocOperations(docs=input_to_docs(actual_content)),
+        terms_per_context=50,
+        text_parser=text_parser)
+
+    pipeline.append(
         BratHtmlEmbeddingPipelineItem(brat_url="http://localhost:8001/")
     )
 
+    no_folding = NoFolding(doc_ids_to_fold=list(range(len(actual_content))),
+                           supported_data_types=[DataType.Test])
+
     backend_template = common.PredictOutputFilepathArg.read_argument(args)
 
-    ppl.run(actual_content, {
+    pipeline.run(None, {
         "template_filepath": join(const.DATA_DIR, "brat_template.html"),
         "predict_fp": "{}.npz".format(backend_template) if backend_template is not None else None,
-        "brat_vis_fp": "{}.html".format(backend_template) if backend_template is not None else None
+        "brat_vis_fp": "{}.html".format(backend_template) if backend_template is not None else None,
+        "data_type_pipelines": {DataType.Test: data_pipeline},
+        "data_folding": no_folding
     })
diff --git a/examples/infer_nn.py b/examples/infer_nn.py
new file mode 100644
index 0000000..692f782
--- /dev/null
+++ b/examples/infer_nn.py
@@ -0,0 +1,121 @@
+import argparse
+from os.path import join
+
+from arekit.common.experiment.data_type import DataType
+from arekit.common.folding.nofold import NoFolding
+from arekit.common.news.entities_grouping import EntitiesGroupingPipelineItem
+from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
+from arekit.common.text.parser import BaseTextParser
+from arekit.contrib.networks.enum_input_types import ModelInputType
+from arekit.contrib.networks.enum_name_types import ModelNames
+from arekit.contrib.utils.pipelines.items.text.frames import FrameVariantsParser
+from arekit.contrib.utils.pipelines.items.text.frames_lemmatized import LemmasBasedFrameVariantsParser
+from arekit.contrib.utils.pipelines.items.text.frames_negation import FrameVariantsSentimentNegation
+from arekit.contrib.utils.pipelines.items.text.terms_splitter import TermsSplitterParser
+from arekit.contrib.utils.pipelines.items.text.tokenizer import DefaultTextTokenizer
+
+from arelight.doc_ops import InMemoryDocOperations
+from arelight.network.nn.common import create_and_fill_variant_collection
+from arelight.pipelines.annot_nolabel import create_neutral_annotation_pipeline
+from arelight.pipelines.demo.infer_nn_rus import demo_infer_texts_tensorflow_nn_pipeline
+from arelight.pipelines.items.backend_brat_html import BratHtmlEmbeddingPipelineItem
+from arelight.pipelines.items.utils import input_to_docs
+from examples.args import const, common, train
+from examples.entities.factory import create_entity_formatter
+from examples.utils import create_labels_scaler, read_synonyms_collection
+
+if __name__ == '__main__':
+
+    parser = argparse.ArgumentParser(description="Text inference example")
+
+    # Providing arguments.
+    common.InputTextArg.add_argument(parser, default=None)
+    common.FromFilesArg.add_argument(parser, default=[const.DEFAULT_TEXT_FILEPATH])
+    common.SynonymsCollectionFilepathArg.add_argument(parser, default=join(const.DATA_DIR, "synonyms.txt"))
+    common.LabelsCountArg.add_argument(parser, default=3)
+    common.ModelNameArg.add_argument(parser, default=ModelNames.PCNN.value)
+    common.TermsPerContextArg.add_argument(parser, default=const.TERMS_PER_CONTEXT)
+    common.EntitiesParserArg.add_argument(parser, default="bert-ontonotes")
+    common.EntityFormatterTypesArg.add_argument(parser, default="hidden-simple-eng")
+    common.VocabFilepathArg.add_argument(parser, default=None)
+    common.EmbeddingMatrixFilepathArg.add_argument(parser, default=None)
+    common.ModelLoadDirArg.add_argument(parser, default=const.NEURAL_NETWORKS_TARGET_DIR)
+    common.StemmerArg.add_argument(parser, default="mystem")
+    common.PredictOutputFilepathArg.add_argument(parser, default=None)
+    common.FramesColectionArg.add_argument(parser)
+    train.BagsPerMinibatchArg.add_argument(parser, default=const.BAGS_PER_MINIBATCH)
+    train.ModelInputTypeArg.add_argument(parser, default=ModelInputType.SingleInstance)
+
+    # Parsing arguments.
+    args = parser.parse_args()
+
+    # Reading provided arguments.
+    model_name = common.ModelNameArg.read_argument(args)
+    model_input_type = train.ModelInputTypeArg.read_argument(args)
+    stemmer = common.StemmerArg.read_argument(args)
+    terms_per_context = common.TermsPerContextArg.read_argument(args)
+    synonyms_filepath = common.SynonymsCollectionFilepathArg.read_argument(args)
+    entities_parser = common.EntitiesParserArg.read_argument(args)
+
+    # Reading text-related parameters.
+    texts_from_files = common.FromFilesArg.read_argument(args)
+    text_from_arg = common.InputTextArg.read_argument(args)
+    input_texts = text_from_arg if text_from_arg is not None else texts_from_files
+
+    # Implement extra structures.
+    labels_scaler = create_labels_scaler(common.LabelsCountArg.read_argument(args))
+
+    # Parsing arguments.
+    args = parser.parse_args()
+
+    synonyms_collection = read_synonyms_collection(
+        filepath=common.SynonymsCollectionFilepathArg.read_argument(args))
+
+    frames_collection = common.FramesColectionArg.read_argument(args)
+
+    demo_pipeline = demo_infer_texts_tensorflow_nn_pipeline(
+        texts_count=len(input_texts),
+        output_dir=const.OUTPUT_DIR,
+        model_name=model_name,
+        model_input_type=model_input_type,
+        frames_collection=frames_collection,
+        model_load_dir=common.ModelLoadDirArg.read_argument(args),
+        entity_fmt=create_entity_formatter(common.EntityFormatterTypesArg.read_argument(args)),
+        bags_per_minibatch=train.BagsPerMinibatchArg.read_argument(args)
+    )
+
+    demo_pipeline.append(BratHtmlEmbeddingPipelineItem(brat_url="http://localhost:8001/"))
+
+    backend_template = common.PredictOutputFilepathArg.read_argument(args)
+
+    doc_ops = InMemoryDocOperations(docs=input_to_docs(input_texts))
+
+    # Initialize text parser with the related dependencies.
+    frame_variants_collection = create_and_fill_variant_collection(frames_collection)
+    text_parser = BaseTextParser(pipeline=[
+        TermsSplitterParser(),
+        entities_parser,
+        EntitiesGroupingPipelineItem(
+            lambda value: SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
+                synonyms_collection, value)),
+        DefaultTextTokenizer(keep_tokens=True),
+        FrameVariantsParser(frame_variants=frame_variants_collection),
+        LemmasBasedFrameVariantsParser(save_lemmas=False,
+                                       stemmer=stemmer,
+                                       frame_variants=frame_variants_collection),
+        FrameVariantsSentimentNegation()])
+
+    test_pipeline = create_neutral_annotation_pipeline(synonyms=synonyms_collection,
+                                                       dist_in_terms_bound=terms_per_context,
+                                                       terms_per_context=terms_per_context,
+                                                       doc_ops=doc_ops,
+                                                       text_parser=text_parser,
+                                                       dist_in_sentences=0)
+
+    demo_pipeline.run(None, {
+        "template_filepath": join(const.DATA_DIR, "brat_template.html"),
+        "predict_fp": "{}.npz".format(backend_template) if backend_template is not None else None,
+        "brat_vis_fp": "{}.html".format(backend_template) if backend_template is not None else None,
+        "data_folding": NoFolding(doc_ids=[0], supported_data_type=DataType.Test),
+        "data_type_pipelines": {DataType.Test: test_pipeline}
+    })
diff --git a/examples/infer_texts_nn.py b/examples/infer_texts_nn.py
deleted file mode 100644
index 0c331c9..0000000
--- a/examples/infer_texts_nn.py
+++ /dev/null
@@ -1,80 +0,0 @@
-import argparse
-from os.path import join
-
-from arekit.common.experiment.name_provider import ExperimentNameProvider
-from arekit.contrib.networks.enum_input_types import ModelInputType
-from arekit.contrib.networks.enum_name_types import ModelNames
-
-from arelight.demo.infer_nn_rus import demo_infer_texts_tensorflow_nn_pipeline
-from arelight.pipelines.backend_brat_html import BratHtmlEmbeddingPipelineItem
-
-from examples.args import const, common, train
-from examples.utils import create_labels_scaler
-
-if __name__ == '__main__':
-
-    parser = argparse.ArgumentParser(description="Text inference example")
-
-    # Providing arguments.
-    common.InputTextArg.add_argument(parser, default=None)
-    common.FromFilesArg.add_argument(parser, default=[const.DEFAULT_TEXT_FILEPATH])
-    common.SynonymsCollectionFilepathArg.add_argument(parser, default=join(const.DATA_DIR, "synonyms.txt"))
-    common.RusVectoresEmbeddingFilepathArg.add_argument(parser, default=const.EMBEDDING_FILEPATH)
-    common.LabelsCountArg.add_argument(parser, default=3)
-    common.ModelNameArg.add_argument(parser, default=ModelNames.PCNN.value)
-    common.TermsPerContextArg.add_argument(parser, default=const.TERMS_PER_CONTEXT)
-    common.EntityFormatterTypesArg.add_argument(parser, default="hidden-simple-eng")
-    common.VocabFilepathArg.add_argument(parser, default=None)
-    common.EmbeddingMatrixFilepathArg.add_argument(parser, default=None)
-    common.ModelLoadDirArg.add_argument(parser, default=const.NEURAL_NETWORKS_TARGET_DIR)
-    common.StemmerArg.add_argument(parser, default="mystem")
-    common.PredictOutputFilepathArg.add_argument(parser, default=None)
-    common.FramesColectionArg.add_argument(parser)
-    train.BagsPerMinibatchArg.add_argument(parser, default=const.BAGS_PER_MINIBATCH)
-    train.ModelInputTypeArg.add_argument(parser, default=ModelInputType.SingleInstance)
-
-    # Parsing arguments.
-    args = parser.parse_args()
-
-    # Reading provided arguments.
-    model_name = common.ModelNameArg.read_argument(args)
-    model_input_type = train.ModelInputTypeArg.read_argument(args)
-
-    # Reading text-related parameters.
-    texts_from_files = common.FromFilesArg.read_argument(args)
-    text_from_arg = common.InputTextArg.read_argument(args)
-    actual_content = text_from_arg if text_from_arg is not None else texts_from_files
-
-    # Implement extra structures.
-    labels_scaler = create_labels_scaler(common.LabelsCountArg.read_argument(args))
-
-    # Parsing arguments.
-    args = parser.parse_args()
-
-    ppl = demo_infer_texts_tensorflow_nn_pipeline(
-        texts_count=len(actual_content),
-        output_dir=const.OUTPUT_DIR,
-        model_name=model_name,
-        model_input_type=model_input_type,
-        exp_name_provider=ExperimentNameProvider(name="example", suffix="infer"),
-        frames_collection=common.FramesColectionArg.read_argument(args),
-        vocab_filepath=common.VocabFilepathArg.read_argument(args),
-        embedding_matrix_filepath=common.EmbeddingMatrixFilepathArg.read_argument(args),
-        embedding_filepath=common.RusVectoresEmbeddingFilepathArg.read_argument(args),
-        model_load_dir=common.ModelLoadDirArg.read_argument(args),
-        terms_per_context=common.TermsPerContextArg.read_argument(args),
-        synonyms_filepath=common.SynonymsCollectionFilepathArg.read_argument(args),
-        entity_fmt_type=common.EntityFormatterTypesArg.read_argument(args),
-        stemmer=common.StemmerArg.read_argument(args),
-        bags_per_minibatch=train.BagsPerMinibatchArg.read_argument(args)
-    )
-
-    ppl.append(BratHtmlEmbeddingPipelineItem(brat_url="http://localhost:8001/"))
-
-    backend_template = common.PredictOutputFilepathArg.read_argument(args)
-
-    ppl.run(actual_content, {
-        "template_filepath": join(const.DATA_DIR, "brat_template.html"),
-        "predict_fp": "{}.npz".format(backend_template) if backend_template is not None else None,
-        "brat_vis_fp": "{}.html".format(backend_template) if backend_template is not None else None
-    })
diff --git a/examples/rusentrel/common.py b/examples/rusentrel/common.py
deleted file mode 100644
index 334f00f..0000000
--- a/examples/rusentrel/common.py
+++ /dev/null
@@ -1,61 +0,0 @@
-from itertools import chain
-
-from arekit.common.experiment.data_type import DataType
-from arekit.common.folding.nofold import NoFolding
-from arekit.contrib.experiment_rusentrel.exp_ds.utils import read_ruattitudes_in_memory
-from arekit.contrib.source.rusentrel.io_utils import RuSentRelIOUtils
-
-from arelight.network.nn.embedding import RusvectoresEmbedding
-
-
-class Common:
-
-    @staticmethod
-    def ra_doc_id_func(doc_id):
-        return 10000 + doc_id
-
-    @staticmethod
-    def create_folding(rusentrel_version, ruattitudes_version, doc_id_func):
-        rsr_indices = list(RuSentRelIOUtils.iter_collection_indices(rusentrel_version))
-
-        ra_indices_dict = dict()
-        if ruattitudes_version is not None:
-            ra_indices_dict = read_ruattitudes_in_memory(version=ruattitudes_version,
-                                                         keep_doc_ids_only=True,
-                                                         doc_id_func=doc_id_func)
-
-        return NoFolding(doc_ids_to_fold=list(chain(rsr_indices, ra_indices_dict.keys())),
-                         supported_data_types=[DataType.Train])
-
-    @staticmethod
-    def create_exp_name(rusentrel_version, ra_version, folding_type):
-        return "".join(["rsr-{v}".format(v=rusentrel_version.value),
-                        "-ra-{v}".format(v=ra_version.value) if ra_version is not None else "",
-                        "-{ft}".format(ft=folding_type.value)])
-
-    @staticmethod
-    def create_exp_name_suffix(use_balancing, terms_per_context, dist_in_terms_between_att_ends):
-        """ Provides an external parameters that assumes to be synchronized both
-            by serialization and training experiment stages.
-        """
-        assert(isinstance(use_balancing, bool))
-        assert(isinstance(terms_per_context, int))
-        assert(isinstance(dist_in_terms_between_att_ends, int) or dist_in_terms_between_att_ends is None)
-
-        # You may provide your own parameters out there
-        params = [
-            u"balanced" if use_balancing else u"nobalance",
-            u"tpc{}".format(terms_per_context)
-        ]
-
-        if dist_in_terms_between_att_ends is not None:
-            params.append(u"dbe{}".format(dist_in_terms_between_att_ends))
-
-        return u'-'.join(params)
-
-    @staticmethod
-    def load_rusvectores_embedding(filepath, stemmer):
-        embedding = RusvectoresEmbedding.from_word2vec_format(filepath=filepath, binary=True)
-        embedding.set_stemmer(stemmer)
-        return embedding
-
diff --git a/examples/rusentrel/config_setups.py b/examples/rusentrel/config_setups.py
deleted file mode 100644
index 8a24871..0000000
--- a/examples/rusentrel/config_setups.py
+++ /dev/null
@@ -1,71 +0,0 @@
-from arekit.contrib.experiment_rusentrel.types import ExperimentTypes
-from arekit.contrib.networks.context.configurations.base.base import DefaultNetworkConfig
-from arekit.contrib.networks.enum_input_types import ModelInputType
-from arekit.contrib.networks.enum_name_types import ModelNames
-from arekit.contrib.networks.multi.configurations.base import BaseMultiInstanceConfig
-
-from examples.rusentrel.configs.common import apply_classic_mi_settings
-from examples.rusentrel.configs.mi import apply_ds_mi_settings
-from examples.rusentrel.configs.single import ctx_self_att_bilstm_custom_config, ctx_att_bilstm_p_zhou_custom_config, \
-    ctx_att_bilstm_z_yang_custom_config, ctx_bilstm_custom_config, ctx_cnn_custom_config, ctx_lstm_custom_config, \
-    ctx_pcnn_custom_config, ctx_rcnn_custom_config, ctx_rcnn_z_yang_custom_config, ctx_rcnn_p_zhou_custom_config
-
-
-def modify_config_for_model(model_name, model_input_type, config):
-    assert(isinstance(model_name, ModelNames))
-    assert(isinstance(model_input_type, ModelInputType))
-    assert (isinstance(config, DefaultNetworkConfig))
-
-    if model_input_type == ModelInputType.SingleInstance:
-        if model_name == ModelNames.SelfAttentionBiLSTM:
-            ctx_self_att_bilstm_custom_config(config)
-        if model_name == ModelNames.AttSelfPZhouBiLSTM:
-            ctx_att_bilstm_p_zhou_custom_config(config)
-        if model_name == ModelNames.AttSelfZYangBiLSTM:
-            ctx_att_bilstm_z_yang_custom_config(config)
-        if model_name == ModelNames.BiLSTM:
-            ctx_bilstm_custom_config(config)
-        if model_name == ModelNames.CNN:
-            ctx_cnn_custom_config(config)
-        if model_name == ModelNames.LSTM:
-            ctx_lstm_custom_config(config)
-        if model_name == ModelNames.PCNN:
-            ctx_pcnn_custom_config(config)
-        if model_name == ModelNames.RCNN:
-            ctx_rcnn_custom_config(config)
-        if model_name == ModelNames.RCNNAttZYang:
-            ctx_rcnn_z_yang_custom_config(config)
-        if model_name == ModelNames.RCNNAttPZhou:
-            ctx_rcnn_p_zhou_custom_config(config)
-
-        return
-
-    if model_input_type == ModelInputType.MultiInstanceMaxPooling or \
-       model_input_type == ModelInputType.MultiInstanceWithSelfAttention:
-        assert(isinstance(config, BaseMultiInstanceConfig))
-
-        # We assign all the settings related to the case of
-        # single instance model, for the related ContextConfig.
-        modify_config_for_model(model_name=model_name,
-                                model_input_type=ModelInputType.SingleInstance,
-                                config=config.ContextConfig)
-
-        # We apply modification of some parameters
-        config.fix_context_parameters()
-        return
-
-    raise NotImplementedError(u"Model input type {input_type} is not supported".format(
-        input_type=model_input_type))
-
-
-def optionally_modify_config_for_experiment(config, exp_type, model_input_type):
-    assert(isinstance(exp_type, ExperimentTypes))
-    assert(isinstance(model_input_type, ModelInputType))
-
-    if model_input_type == ModelInputType.MultiInstanceMaxPooling:
-        if exp_type == ExperimentTypes.RuSentRel:
-            apply_classic_mi_settings(config)
-        if exp_type == ExperimentTypes.RuAttitudes or exp_type == ExperimentTypes.RuSentRelWithRuAttitudes:
-            apply_ds_mi_settings(config)
-
-        return
diff --git a/examples/rusentrel/configs/common.py b/examples/rusentrel/configs/common.py
deleted file mode 100644
index db77fc5..0000000
--- a/examples/rusentrel/configs/common.py
+++ /dev/null
@@ -1,14 +0,0 @@
-from arekit.contrib.networks.multi.configurations.base import BaseMultiInstanceConfig
-
-from examples.args.const import BAGS_PER_MINIBATCH
-
-MI_CONTEXTS_PER_OPINION = 3
-
-
-def apply_classic_mi_settings(config):
-    """
-    Multi instance version
-    """
-    assert(isinstance(config, BaseMultiInstanceConfig))
-    config.set_contexts_per_opinion(MI_CONTEXTS_PER_OPINION)
-    config.modify_bags_per_minibatch(BAGS_PER_MINIBATCH)
diff --git a/examples/rusentrel/configs/mi.py b/examples/rusentrel/configs/mi.py
deleted file mode 100644
index 8996de3..0000000
--- a/examples/rusentrel/configs/mi.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from arekit.contrib.networks.multi.configurations.base import BaseMultiInstanceConfig
-
-from examples.rusentrel.configs.common import MI_CONTEXTS_PER_OPINION
-
-
-def apply_ds_mi_settings(config):
-    """
-    This function describes a base config setup for all models.
-    """
-    assert(isinstance(config, BaseMultiInstanceConfig))
-    config.set_contexts_per_opinion(MI_CONTEXTS_PER_OPINION)
-    config.modify_bags_per_minibatch(2)
\ No newline at end of file
diff --git a/examples/rusentrel/configs/single.py b/examples/rusentrel/configs/single.py
deleted file mode 100644
index 0b736d4..0000000
--- a/examples/rusentrel/configs/single.py
+++ /dev/null
@@ -1,76 +0,0 @@
-import tensorflow as tf
-
-from arekit.contrib.networks.context.configurations.att_self_p_zhou_bilstm import AttentionSelfPZhouBiLSTMConfig
-from arekit.contrib.networks.context.configurations.att_self_z_yang_bilstm import AttentionSelfZYangBiLSTMConfig
-from arekit.contrib.networks.context.configurations.bilstm import BiLSTMConfig
-from arekit.contrib.networks.context.configurations.cnn import CNNConfig
-from arekit.contrib.networks.context.configurations.rcnn import RCNNConfig
-from arekit.contrib.networks.context.configurations.rnn import RNNConfig
-from arekit.contrib.networks.context.configurations.self_att_bilstm import SelfAttentionBiLSTMConfig
-from arekit.contrib.networks.tf_helpers.cell_types import CellTypes
-
-from examples.args.const import TERMS_PER_CONTEXT
-
-
-def ctx_self_att_bilstm_custom_config(config):
-    assert(isinstance(config, SelfAttentionBiLSTMConfig))
-    config.modify_penaltization_term_coef(0.5)
-    config.modify_cell_type(CellTypes.BasicLSTM)
-    config.modify_dropout_rnn_keep_prob(0.8)
-    config.modify_terms_per_context(TERMS_PER_CONTEXT)
-
-
-def ctx_att_bilstm_p_zhou_custom_config(config):
-    assert(isinstance(config, AttentionSelfPZhouBiLSTMConfig))
-    config.modify_hidden_size(128)
-    config.modify_cell_type(CellTypes.LSTM)
-    config.modify_dropout_rnn_keep_prob(0.9)
-
-
-def ctx_att_bilstm_z_yang_custom_config(config):
-    assert(isinstance(config, AttentionSelfZYangBiLSTMConfig))
-    config.modify_weight_initializer(tf.contrib.layers.xavier_initializer())
-
-
-def ctx_bilstm_custom_config(config):
-    assert(isinstance(config, BiLSTMConfig))
-    config.modify_hidden_size(128)
-    config.modify_cell_type(CellTypes.BasicLSTM)
-    config.modify_dropout_rnn_keep_prob(0.8)
-    config.modify_terms_per_context(TERMS_PER_CONTEXT)
-
-
-def ctx_cnn_custom_config(config):
-    assert(isinstance(config, CNNConfig))
-    config.modify_weight_initializer(tf.contrib.layers.xavier_initializer())
-
-
-def ctx_lstm_custom_config(config):
-    assert(isinstance(config, RNNConfig))
-    config.modify_cell_type(CellTypes.BasicLSTM)
-    config.modify_hidden_size(128)
-    config.modify_dropout_rnn_keep_prob(0.8)
-    config.modify_terms_per_context(TERMS_PER_CONTEXT)
-
-
-def ctx_pcnn_custom_config(config):
-    assert(isinstance(config, CNNConfig))
-    config.modify_weight_initializer(tf.contrib.layers.xavier_initializer())
-
-
-def ctx_rcnn_custom_config(config):
-    assert(isinstance(config, RCNNConfig))
-    config.modify_cell_type(CellTypes.LSTM)
-    config.modify_dropout_rnn_keep_prob(0.9)
-
-
-def ctx_rcnn_p_zhou_custom_config(config):
-    assert(isinstance(config, RCNNConfig))
-    config.modify_cell_type(CellTypes.LSTM)
-    config.modify_dropout_rnn_keep_prob(0.9)
-
-
-def ctx_rcnn_z_yang_custom_config(config):
-    assert(isinstance(config, RCNNConfig))
-    config.modify_cell_type(CellTypes.LSTM)
-    config.modify_dropout_rnn_keep_prob(0.9)
\ No newline at end of file
diff --git a/examples/rusentrel/exp_io.py b/examples/rusentrel/exp_io.py
deleted file mode 100644
index f22780d..0000000
--- a/examples/rusentrel/exp_io.py
+++ /dev/null
@@ -1,11 +0,0 @@
-from arekit.contrib.experiment_rusentrel.model_io.tf_networks import RuSentRelExperimentNetworkIOUtils
-from examples.args.const import OUTPUT_DIR
-
-
-class CustomRuSentRelNetworkExperimentIO(RuSentRelExperimentNetworkIOUtils):
-
-    def try_prepare(self):
-        pass
-
-    def _get_experiment_sources_dir(self):
-        return OUTPUT_DIR
diff --git a/examples/serialize_bert.py b/examples/serialize_bert.py
new file mode 100644
index 0000000..eba486a
--- /dev/null
+++ b/examples/serialize_bert.py
@@ -0,0 +1,106 @@
+import argparse
+from os.path import join
+
+from arekit.common.experiment.data_type import DataType
+from arekit.common.folding.nofold import NoFolding
+from arekit.common.labels.base import NoLabel
+from arekit.common.labels.provider.constant import ConstantLabelProvider
+from arekit.common.labels.scaler.single import SingleLabelScaler
+from arekit.common.labels.str_fmt import StringLabelsFormatter
+from arekit.common.news.entities_grouping import EntitiesGroupingPipelineItem
+from arekit.common.opinions.annot.algo.pair_based import PairBasedOpinionAnnotationAlgorithm
+from arekit.common.opinions.annot.base import BaseOpinionAnnotator
+from arekit.common.pipeline.base import BasePipeline
+from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
+from arekit.common.text.parser import BaseTextParser
+from arekit.contrib.utils.io_utils.samples import SamplesIO
+from arekit.contrib.utils.pipelines.items.sampling.bert import BertExperimentInputSerializerPipelineItem
+from arekit.contrib.utils.pipelines.items.text.terms_splitter import TermsSplitterParser
+
+from arelight.doc_ops import InMemoryDocOperations
+from arelight.pipelines.annot_nolabel import create_neutral_annotation_pipeline
+from arelight.pipelines.items.utils import input_to_docs
+from arelight.samplers.bert import create_bert_sample_provider
+from arelight.samplers.types import BertSampleProviderTypes
+
+from examples.args import const, common
+from examples.args.const import DEFAULT_TEXT_FILEPATH
+from examples.entities.factory import create_entity_formatter
+from examples.utils import read_synonyms_collection
+
+
+if __name__ == '__main__':
+
+    parser = argparse.ArgumentParser(description="Serialization script for obtaining sources, "
+                                                 "required for inference and training.")
+
+    # Provide arguments.
+    common.InputTextArg.add_argument(parser, default=None)
+    common.FromFilesArg.add_argument(parser, default=[DEFAULT_TEXT_FILEPATH])
+    common.EntitiesParserArg.add_argument(parser, default="bert-ontonotes")
+    common.TermsPerContextArg.add_argument(parser, default=const.TERMS_PER_CONTEXT)
+    common.EntityFormatterTypesArg.add_argument(parser, default="hidden-bert-styled")
+    common.SynonymsCollectionFilepathArg.add_argument(parser, default=join(const.DATA_DIR, "synonyms.txt"))
+    common.BertTextBFormatTypeArg.add_argument(parser, default='nli_m')
+
+    # Parsing arguments.
+    args = parser.parse_args()
+
+    # Parsing arguments.
+    text_from_arg = common.InputTextArg.read_argument(args)
+    texts_from_files = common.FromFilesArg.read_argument(args)
+    entities_parser = common.EntitiesParserArg.read_argument(args)
+    entity_fmt = create_entity_formatter(common.EntityFormatterTypesArg.read_argument(args))
+    input_texts = text_from_arg if text_from_arg is not None else texts_from_files
+    opin_annot = BaseOpinionAnnotator()
+    doc_ops = InMemoryDocOperations(docs=input_to_docs(input_texts))
+    labels_fmt = StringLabelsFormatter(stol={"neu": NoLabel})
+    label_scaler = SingleLabelScaler(NoLabel())
+
+    synonyms = read_synonyms_collection(
+        filepath=common.SynonymsCollectionFilepathArg.read_argument(args))
+
+    annot_algo = PairBasedOpinionAnnotationAlgorithm(
+        dist_in_terms_bound=None,
+        label_provider=ConstantLabelProvider(label_instance=NoLabel()))
+
+    # Declare text parser.
+    text_parser = BaseTextParser(pipeline=[
+        TermsSplitterParser(),
+        entities_parser,
+        EntitiesGroupingPipelineItem(lambda value:
+            SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
+                synonyms=synonyms, value=value))
+    ])
+
+    terms_per_context = common.TermsPerContextArg.read_argument(args)
+
+    # Initialize data processing pipeline.
+    test_pipeline = create_neutral_annotation_pipeline(synonyms=synonyms,
+                                                       dist_in_terms_bound=terms_per_context,
+                                                       terms_per_context=terms_per_context,
+                                                       doc_ops=doc_ops,
+                                                       text_parser=text_parser,
+                                                       dist_in_sentences=0)
+
+    rows_provider = create_bert_sample_provider(
+        label_scaler=label_scaler,
+        provider_type=BertSampleProviderTypes.NLI_M,
+        text_b_labels_fmt=labels_fmt,
+        entity_formatter=entity_fmt)
+
+    pipeline = BasePipeline([
+        BertExperimentInputSerializerPipelineItem(
+            sample_rows_provider=rows_provider,
+            samples_io=SamplesIO(target_dir=const.OUTPUT_DIR),
+            save_labels_func=lambda data_type: data_type != DataType.Test,
+            balance_func=lambda data_type: data_type == DataType.Train)
+    ])
+
+    no_folding = NoFolding(doc_ids=list(range(len(texts_from_files))), supported_data_type=DataType.Test)
+
+    pipeline.run(input_data=None,
+                 params_dict={
+                     "data_folding": no_folding,
+                     "data_type_pipelines": {DataType.Test: test_pipeline}
+                 })
diff --git a/examples/serialize_nn.py b/examples/serialize_nn.py
new file mode 100644
index 0000000..5b669a8
--- /dev/null
+++ b/examples/serialize_nn.py
@@ -0,0 +1,125 @@
+import argparse
+from os.path import join
+
+from arekit.common.experiment.data_type import DataType
+from arekit.common.folding.nofold import NoFolding
+from arekit.common.labels.base import NoLabel
+from arekit.common.labels.provider.constant import ConstantLabelProvider
+from arekit.common.news.entities_grouping import EntitiesGroupingPipelineItem
+from arekit.common.opinions.annot.algo.pair_based import PairBasedOpinionAnnotationAlgorithm
+from arekit.common.pipeline.base import BasePipeline
+from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
+from arekit.common.text.parser import BaseTextParser
+from arekit.contrib.networks.core.input.term_types import TermTypes
+from arekit.contrib.utils.io_utils.embedding import NpEmbeddingIO
+from arekit.contrib.utils.io_utils.samples import SamplesIO
+from arekit.contrib.utils.pipelines.items.sampling.networks import NetworksInputSerializerPipelineItem
+from arekit.contrib.utils.pipelines.items.text.frames import FrameVariantsParser
+from arekit.contrib.utils.pipelines.items.text.frames_lemmatized import LemmasBasedFrameVariantsParser
+from arekit.contrib.utils.pipelines.items.text.frames_negation import FrameVariantsSentimentNegation
+from arekit.contrib.utils.pipelines.items.text.terms_splitter import TermsSplitterParser
+from arekit.contrib.utils.pipelines.items.text.tokenizer import DefaultTextTokenizer
+from arekit.contrib.utils.processing.lemmatization.mystem import MystemWrapper
+from arekit.contrib.utils.processing.pos.mystem_wrap import POSMystemWrapper
+from arekit.contrib.utils.resources import load_embedding_news_mystem_skipgram_1000_20_2015
+from arekit.contrib.utils.vectorizers.bpe import BPEVectorizer
+from arekit.contrib.utils.vectorizers.random_norm import RandomNormalVectorizer
+
+from arelight.doc_ops import InMemoryDocOperations
+from arelight.network.nn.common import create_and_fill_variant_collection
+from arelight.network.nn.ctx import CustomNeuralNetworkSerializationContext
+from arelight.pipelines.annot_nolabel import create_neutral_annotation_pipeline
+from arelight.pipelines.items.utils import input_to_docs
+
+from examples.args import const
+from examples.args import common
+from examples.args.const import DEFAULT_TEXT_FILEPATH
+from examples.entities.factory import create_entity_formatter
+from examples.utils import read_synonyms_collection, create_labels_scaler
+
+if __name__ == '__main__':
+
+    parser = argparse.ArgumentParser(description="Serialization script for obtaining sources, "
+                                                 "required for inference and training.")
+
+    # Provide arguments.
+    common.InputTextArg.add_argument(parser, default=None)
+    common.FromFilesArg.add_argument(parser, default=[DEFAULT_TEXT_FILEPATH])
+    common.SynonymsCollectionFilepathArg.add_argument(parser, default=join(const.DATA_DIR, "synonyms.txt"))
+    common.EntitiesParserArg.add_argument(parser, default="bert-ontonotes")
+    common.TermsPerContextArg.add_argument(parser, default=const.TERMS_PER_CONTEXT)
+    common.EntityFormatterTypesArg.add_argument(parser, default="hidden-simple-eng")
+    common.StemmerArg.add_argument(parser, default="mystem")
+    common.FramesColectionArg.add_argument(parser)
+
+    # Parsing arguments.
+    args = parser.parse_args()
+
+    text_from_arg = common.InputTextArg.read_argument(args)
+    texts_from_files = common.FromFilesArg.read_argument(args)
+    input_texts = text_from_arg if text_from_arg is not None else texts_from_files
+    synonyms_collection = read_synonyms_collection(
+        filepath=common.SynonymsCollectionFilepathArg.read_argument(args))
+    annot_algo = PairBasedOpinionAnnotationAlgorithm(
+        dist_in_terms_bound=None, label_provider=ConstantLabelProvider(label_instance=NoLabel()))
+    terms_per_context = common.TermsPerContextArg.read_argument(args)
+    entities_parser = common.EntitiesParserArg.read_argument(args)
+    frames_collection = common.FramesColectionArg.read_argument(args)
+    doc_ops = InMemoryDocOperations(docs=input_to_docs(input_texts))
+    stemmer = common.StemmerArg.read_argument(args)
+
+    ctx = CustomNeuralNetworkSerializationContext(
+        labels_scaler=create_labels_scaler(3),
+        pos_tagger=POSMystemWrapper(MystemWrapper().MystemInstance),
+        frames_collection=frames_collection)
+
+    embedding = load_embedding_news_mystem_skipgram_1000_20_2015(stemmer)
+    bpe_vectorizer = BPEVectorizer(embedding=embedding, max_part_size=3)
+    norm_vectorizer = RandomNormalVectorizer(vector_size=embedding.VectorSize,
+                                             token_offset=12345)
+
+    pipeline = BasePipeline([
+        NetworksInputSerializerPipelineItem(
+            vectorizers={
+                TermTypes.WORD: bpe_vectorizer,
+                TermTypes.ENTITY: bpe_vectorizer,
+                TermTypes.FRAME: bpe_vectorizer,
+                TermTypes.TOKEN: norm_vectorizer
+            },
+            str_entity_fmt=create_entity_formatter(common.EntityFormatterTypesArg.read_argument(args)),
+            ctx=ctx,
+            samples_io=SamplesIO(target_dir=const.OUTPUT_DIR),
+            emb_io=NpEmbeddingIO(target_dir=const.OUTPUT_DIR),
+            save_labels_func=lambda data_type: data_type != DataType.Test,
+            balance_func=lambda data_type: data_type == DataType.Train,
+            save_embedding=True)
+    ])
+
+    # Initialize text parser with the related dependencies.
+    frame_variants_collection = create_and_fill_variant_collection(frames_collection)
+    text_parser = BaseTextParser(pipeline=[
+        TermsSplitterParser(),
+        entities_parser,
+        EntitiesGroupingPipelineItem(
+            lambda value: SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
+                synonyms_collection, value)),
+        DefaultTextTokenizer(keep_tokens=True),
+        FrameVariantsParser(frame_variants=frame_variants_collection),
+        LemmasBasedFrameVariantsParser(save_lemmas=False,
+                                       stemmer=stemmer,
+                                       frame_variants=frame_variants_collection),
+        FrameVariantsSentimentNegation()])
+
+    # Initialize data processing pipeline.
+    test_pipeline = create_neutral_annotation_pipeline(synonyms=synonyms_collection,
+                                                       dist_in_terms_bound=terms_per_context,
+                                                       terms_per_context=terms_per_context,
+                                                       doc_ops=doc_ops,
+                                                       text_parser=text_parser,
+                                                       dist_in_sentences=0)
+
+    pipeline.run(input_data=None,
+                 params_dict={
+                     "data_folding": NoFolding(doc_ids_to_fold=[0], supported_data_types=[DataType.Test]),
+                     "data_type_pipelines": {DataType.Test: test_pipeline}
+                 })
diff --git a/examples/serialize_rusentrel_for_bert.py b/examples/serialize_rusentrel_for_bert.py
deleted file mode 100644
index 5d30c63..0000000
--- a/examples/serialize_rusentrel_for_bert.py
+++ /dev/null
@@ -1,123 +0,0 @@
-import argparse
-
-from arekit.common.experiment.annot.algo.pair_based import PairBasedAnnotationAlgorithm
-from arekit.common.experiment.annot.default import DefaultAnnotator
-from arekit.common.experiment.engine import ExperimentEngine
-from arekit.common.experiment.name_provider import ExperimentNameProvider
-from arekit.common.folding.types import FoldingType
-from arekit.common.labels.provider.constant import ConstantLabelProvider
-from arekit.common.labels.str_fmt import StringLabelsFormatter
-from arekit.contrib.bert.handlers.serializer import BertExperimentInputSerializerIterationHandler
-from arekit.contrib.experiment_rusentrel.entities.factory import create_entity_formatter
-from arekit.contrib.experiment_rusentrel.factory import create_experiment
-from arekit.contrib.experiment_rusentrel.labels.types import ExperimentNeutralLabel, ExperimentPositiveLabel, \
-    ExperimentNegativeLabel
-from arekit.contrib.experiment_rusentrel.synonyms.provider import RuSentRelSynonymsCollectionProvider
-from arekit.contrib.experiment_rusentrel.types import ExperimentTypes
-from arekit.contrib.source.rusentrel.io_utils import RuSentRelVersions
-
-from examples.args import const, common
-from examples.args.const import DEFAULT_TEXT_FILEPATH
-from examples.rusentrel.common import Common
-from examples.rusentrel.exp_io import CustomRuSentRelNetworkExperimentIO
-
-from arelight.network.bert.ctx import BertSerializationContext
-from examples.utils import create_labels_scaler
-
-
-class ExperimentBERTTextBThreeScaleLabelsFormatter(StringLabelsFormatter):
-
-    def __init__(self):
-        stol = {'neu': ExperimentNeutralLabel,
-                'pos': ExperimentPositiveLabel,
-                'neg': ExperimentNegativeLabel}
-        super(ExperimentBERTTextBThreeScaleLabelsFormatter, self).__init__(stol=stol)
-
-
-if __name__ == '__main__':
-
-    parser = argparse.ArgumentParser(description="Serialization script for obtaining sources, "
-                                                 "required for inference and training.")
-
-    # Provide arguments.
-    common.InputTextArg.add_argument(parser, default=None)
-    common.FromFilesArg.add_argument(parser, default=[DEFAULT_TEXT_FILEPATH])
-    common.EntitiesParserArg.add_argument(parser, default="bert-ontonotes")
-    common.RusVectoresEmbeddingFilepathArg.add_argument(parser, default=const.EMBEDDING_FILEPATH)
-    common.TermsPerContextArg.add_argument(parser, default=const.TERMS_PER_CONTEXT)
-    common.UseBalancingArg.add_argument(parser, default=True)
-    common.DistanceInTermsBetweenAttitudeEndsArg.add_argument(parser, default=None)
-    common.EntityFormatterTypesArg.add_argument(parser, default="hidden-bert-styled")
-    common.BertTextBFormatTypeArg.add_argument(parser, default='nli_m')
-    common.StemmerArg.add_argument(parser, default="mystem")
-
-    # Parsing arguments.
-    args = parser.parse_args()
-
-    # Reading arguments.
-    text_from_arg = common.InputTextArg.read_argument(args)
-    texts_from_files = common.FromFilesArg.read_argument(args)
-    terms_per_context = common.TermsPerContextArg.read_argument(args)
-    use_balancing = common.UseBalancingArg.read_argument(args)
-    stemmer = common.StemmerArg.read_argument(args)
-    entity_fmt = common.EntityFormatterTypesArg.read_argument(args)
-    dist_in_terms_between_attitude_ends = common.DistanceInTermsBetweenAttitudeEndsArg.read_argument(args)
-
-    # Predefined parameters.
-    labels_count = 3
-    rusentrel_version = RuSentRelVersions.V11
-    synonyms = RuSentRelSynonymsCollectionProvider.load_collection(stemmer=stemmer)
-    folding_type = FoldingType.Fixed
-
-    annot_algo = PairBasedAnnotationAlgorithm(
-        dist_in_terms_bound=None,
-        label_provider=ConstantLabelProvider(label_instance=ExperimentNeutralLabel()))
-
-    exp_name = Common.create_exp_name(rusentrel_version=rusentrel_version,
-                                      ra_version=None,
-                                      folding_type=folding_type)
-
-    extra_name_suffix = Common.create_exp_name_suffix(
-        use_balancing=use_balancing,
-        terms_per_context=terms_per_context,
-        dist_in_terms_between_att_ends=dist_in_terms_between_attitude_ends)
-
-    data_folding = Common.create_folding(
-        rusentrel_version=rusentrel_version,
-        ruattitudes_version=None,
-        doc_id_func=lambda doc_id: Common.ra_doc_id_func(doc_id=doc_id))
-
-    # Preparing necessary structures for further initializations.
-    exp_ctx = BertSerializationContext(
-        label_scaler=create_labels_scaler(labels_count),
-        terms_per_context=terms_per_context,
-        str_entity_formatter=create_entity_formatter(entity_fmt),
-        annotator=DefaultAnnotator(annot_algo=annot_algo),
-        name_provider=ExperimentNameProvider(name=exp_name, suffix=extra_name_suffix + "-bert"),
-        data_folding=data_folding)
-
-    experiment = create_experiment(
-        exp_type=ExperimentTypes.RuSentRel,
-        exp_ctx=exp_ctx,
-        exp_io=CustomRuSentRelNetworkExperimentIO(exp_ctx),
-        folding_type=folding_type,
-        rusentrel_version=rusentrel_version,
-        ruattitudes_version=None,
-        load_ruattitude_docs=True,
-        ra_doc_id_func=lambda doc_id: Common.ra_doc_id_func(doc_id=doc_id))
-
-    handler = BertExperimentInputSerializerIterationHandler(
-        exp_io=experiment.ExperimentIO,
-        exp_ctx=experiment.ExperimentContext,
-        doc_ops=experiment.DocumentOperations,
-        opin_ops=experiment.OpinionOperations,
-        sample_labels_fmt=ExperimentBERTTextBThreeScaleLabelsFormatter(),
-        annot_labels_fmt=experiment.OpinionOperations.LabelsFormatter,
-        sample_provider_type=common.BertTextBFormatTypeArg.read_argument(args),
-        entity_formatter=experiment.ExperimentContext.StringEntityFormatter,
-        value_to_group_id_func=synonyms.get_synonym_group_index,
-        balance_train_samples=use_balancing)
-
-    engine = ExperimentEngine(exp_ctx.DataFolding)
-
-    engine.run(handlers=[handler])
diff --git a/examples/serialize_rusentrel_for_nn.py b/examples/serialize_rusentrel_for_nn.py
deleted file mode 100644
index f0b3f6e..0000000
--- a/examples/serialize_rusentrel_for_nn.py
+++ /dev/null
@@ -1,120 +0,0 @@
-import argparse
-
-from arelight.network.nn.common import create_and_fill_variant_collection
-from arelight.network.nn.ctx import NetworkSerializationContext
-
-from examples.args import const, common
-
-from arekit.common.experiment.annot.algo.pair_based import PairBasedAnnotationAlgorithm
-from arekit.common.experiment.annot.default import DefaultAnnotator
-from arekit.common.experiment.engine import ExperimentEngine
-from arekit.common.experiment.name_provider import ExperimentNameProvider
-from arekit.common.folding.types import FoldingType
-from arekit.common.labels.provider.constant import ConstantLabelProvider
-from arekit.contrib.experiment_rusentrel.entities.factory import create_entity_formatter
-from arekit.contrib.experiment_rusentrel.factory import create_experiment
-from arekit.contrib.experiment_rusentrel.labels.types import ExperimentNeutralLabel
-from arekit.contrib.experiment_rusentrel.synonyms.provider import RuSentRelSynonymsCollectionProvider
-from arekit.contrib.experiment_rusentrel.types import ExperimentTypes
-from arekit.contrib.networks.handlers.serializer import NetworksInputSerializerExperimentIteration
-from arekit.contrib.source.rusentrel.io_utils import RuSentRelVersions
-from arekit.processing.lemmatization.mystem import MystemWrapper
-from arekit.processing.pos.mystem_wrap import POSMystemWrapper
-from arekit.processing.text.pipeline_frames_lemmatized import LemmasBasedFrameVariantsParser
-from arekit.processing.text.pipeline_tokenizer import DefaultTextTokenizer
-
-from examples.rusentrel.common import Common
-from examples.rusentrel.exp_io import CustomRuSentRelNetworkExperimentIO
-from examples.utils import create_labels_scaler
-
-if __name__ == '__main__':
-
-    parser = argparse.ArgumentParser(description="RuSentRel dataset serialization script")
-
-    # Provide arguments.
-    common.LabelsCountArg.add_argument(parser, default=3)
-    common.RusVectoresEmbeddingFilepathArg.add_argument(parser, default=const.EMBEDDING_FILEPATH)
-    common.TermsPerContextArg.add_argument(parser, default=const.TERMS_PER_CONTEXT)
-    common.EntityFormatterTypesArg.add_argument(parser, default="hidden-simple-eng")
-    common.StemmerArg.add_argument(parser, default="mystem")
-    common.UseBalancingArg.add_argument(parser, default=True)
-    common.DistanceInTermsBetweenAttitudeEndsArg.add_argument(parser, default=None)
-    common.FramesColectionArg.add_argument(parser)
-
-    # Parsing arguments.
-    args = parser.parse_args()
-
-    # Reading arguments.
-    embedding_filepath = common.RusVectoresEmbeddingFilepathArg.read_argument(args)
-    labels_count = common.LabelsCountArg.read_argument(args)
-    terms_per_context = common.TermsPerContextArg.read_argument(args)
-    entity_fmt = common.EntityFormatterTypesArg.read_argument(args)
-    stemmer = common.StemmerArg.read_argument(args)
-    use_balancing = common.UseBalancingArg.read_argument(args)
-    dist_in_terms_between_attitude_ends = common.DistanceInTermsBetweenAttitudeEndsArg.read_argument(args)
-    frames_collection = common.FramesColectionArg.read_argument(args)
-    pos_tagger = POSMystemWrapper(MystemWrapper().MystemInstance)
-
-    # Default parameters
-    rusentrel_version = RuSentRelVersions.V11
-    folding_type = FoldingType.Fixed
-
-    synonyms_collection = RuSentRelSynonymsCollectionProvider.load_collection(stemmer=stemmer)
-
-    annot_algo = PairBasedAnnotationAlgorithm(
-        dist_in_terms_bound=None,
-        label_provider=ConstantLabelProvider(label_instance=ExperimentNeutralLabel()))
-
-    exp_name = Common.create_exp_name(rusentrel_version=rusentrel_version,
-                                      ra_version=None,
-                                      folding_type=folding_type)
-
-    extra_name_suffix = Common.create_exp_name_suffix(
-        use_balancing=use_balancing,
-        terms_per_context=terms_per_context,
-        dist_in_terms_between_att_ends=dist_in_terms_between_attitude_ends)
-
-    data_folding = Common.create_folding(
-        rusentrel_version=rusentrel_version,
-        ruattitudes_version=None,
-        doc_id_func=lambda doc_id: Common.ra_doc_id_func(doc_id=doc_id))
-
-    # Preparing necessary structures for further initializations.
-    exp_ctx = NetworkSerializationContext(
-        labels_scaler=create_labels_scaler(labels_count),
-        embedding=Common.load_rusvectores_embedding(filepath=embedding_filepath, stemmer=stemmer),
-        terms_per_context=terms_per_context,
-        str_entity_formatter=create_entity_formatter(entity_fmt),
-        pos_tagger=pos_tagger,
-        annotator=DefaultAnnotator(annot_algo=annot_algo),
-        name_provider=ExperimentNameProvider(name=exp_name, suffix=extra_name_suffix),
-        frames_collection=frames_collection,
-        frame_variant_collection=create_and_fill_variant_collection(frames_collection),
-        data_folding=data_folding)
-
-    experiment = create_experiment(
-        exp_type=ExperimentTypes.RuSentRel,
-        exp_ctx=exp_ctx,
-        exp_io=CustomRuSentRelNetworkExperimentIO(exp_ctx),
-        folding_type=folding_type,
-        rusentrel_version=rusentrel_version,
-        ruattitudes_version=None,
-        load_ruattitude_docs=True,
-        text_parser_items=[
-            DefaultTextTokenizer(keep_tokens=True),
-            LemmasBasedFrameVariantsParser(frame_variants=exp_ctx.FrameVariantCollection, stemmer=stemmer)
-        ],
-        ra_doc_id_func=lambda doc_id: Common.ra_doc_id_func(doc_id=doc_id))
-
-    # Performing serialization process.
-    serialization_handler = NetworksInputSerializerExperimentIteration(
-        exp_ctx=experiment.ExperimentContext,
-        doc_ops=experiment.DocumentOperations,
-        opin_ops=experiment.OpinionOperations,
-        exp_io=experiment.ExperimentIO,
-        balance=use_balancing,
-        value_to_group_id_func=synonyms_collection.get_synonym_group_index)
-
-    engine = ExperimentEngine(exp_ctx.DataFolding)
-
-    engine.run(handlers=[serialization_handler])
diff --git a/examples/serialize_texts_bert.py b/examples/serialize_texts_bert.py
deleted file mode 100644
index 6b011fc..0000000
--- a/examples/serialize_texts_bert.py
+++ /dev/null
@@ -1,58 +0,0 @@
-import argparse
-from os.path import join
-
-from arekit.common.experiment.annot.algo.pair_based import PairBasedAnnotationAlgorithm
-from arekit.common.experiment.annot.default import DefaultAnnotator
-from arekit.common.experiment.data_type import DataType
-from arekit.common.experiment.name_provider import ExperimentNameProvider
-from arekit.common.folding.nofold import NoFolding
-from arekit.common.labels.base import NoLabel
-from arekit.common.labels.provider.constant import ConstantLabelProvider
-from arekit.common.pipeline.base import BasePipeline
-from arekit.contrib.experiment_rusentrel.entities.factory import create_entity_formatter
-from arelight.pipelines.serialize_bert import BertTextsSerializationPipelineItem
-
-from examples.args import const, common
-from examples.args.const import DEFAULT_TEXT_FILEPATH
-from examples.utils import read_synonyms_collection
-
-if __name__ == '__main__':
-
-    parser = argparse.ArgumentParser(description="Serialization script for obtaining sources, "
-                                                 "required for inference and training.")
-
-    # Provide arguments.
-    common.InputTextArg.add_argument(parser, default=None)
-    common.FromFilesArg.add_argument(parser, default=[DEFAULT_TEXT_FILEPATH])
-    common.EntitiesParserArg.add_argument(parser, default="bert-ontonotes")
-    common.TermsPerContextArg.add_argument(parser, default=const.TERMS_PER_CONTEXT)
-    common.EntityFormatterTypesArg.add_argument(parser, default="hidden-bert-styled")
-    common.SynonymsCollectionFilepathArg.add_argument(parser, default=join(const.DATA_DIR, "synonyms.txt"))
-    common.BertTextBFormatTypeArg.add_argument(parser, default='nli_m')
-
-    # Parsing arguments.
-    args = parser.parse_args()
-
-    text_from_arg = common.InputTextArg.read_argument(args)
-    texts_from_files = common.FromFilesArg.read_argument(args)
-
-    synonyms_collection = read_synonyms_collection(
-        filepath=common.SynonymsCollectionFilepathArg.read_argument(args))
-
-    ppl = BasePipeline([
-        BertTextsSerializationPipelineItem(
-            terms_per_context=common.TermsPerContextArg.read_argument(args),
-            synonyms=synonyms_collection,
-            output_dir=const.OUTPUT_DIR,
-            entities_parser=common.EntitiesParserArg.read_argument(args),
-            name_provider=ExperimentNameProvider(name="example-bert", suffix="serialize"),
-            entity_fmt=create_entity_formatter(common.EntityFormatterTypesArg.read_argument(args)),
-            text_b_type=common.BertTextBFormatTypeArg.read_argument(args),
-            opin_annot=DefaultAnnotator(annot_algo=PairBasedAnnotationAlgorithm(
-                dist_in_terms_bound=None,
-                label_provider=ConstantLabelProvider(label_instance=NoLabel()))),
-            data_folding=NoFolding(doc_ids_to_fold=list(range(len(texts_from_files))),
-                                   supported_data_types=[DataType.Test]))
-    ])
-
-    ppl.run(text_from_arg if text_from_arg is not None else texts_from_files)
diff --git a/examples/serialize_texts_nn.py b/examples/serialize_texts_nn.py
deleted file mode 100644
index dd4d225..0000000
--- a/examples/serialize_texts_nn.py
+++ /dev/null
@@ -1,63 +0,0 @@
-import argparse
-from os.path import join
-
-from arekit.common.experiment.annot.algo.pair_based import PairBasedAnnotationAlgorithm
-from arekit.common.experiment.annot.default import DefaultAnnotator
-from arekit.common.experiment.data_type import DataType
-from arekit.common.experiment.name_provider import ExperimentNameProvider
-from arekit.common.folding.nofold import NoFolding
-from arekit.common.labels.base import NoLabel
-from arekit.common.labels.provider.constant import ConstantLabelProvider
-from arekit.common.pipeline.base import BasePipeline
-from arekit.contrib.experiment_rusentrel.entities.factory import create_entity_formatter
-
-from examples.args import const
-from examples.args import common
-from examples.args.const import DEFAULT_TEXT_FILEPATH
-
-from arelight.pipelines.serialize_nn import NetworkTextsSerializationPipelineItem
-from examples.utils import read_synonyms_collection
-
-if __name__ == '__main__':
-
-    parser = argparse.ArgumentParser(description="Serialization script for obtaining sources, "
-                                                 "required for inference and training.")
-
-    # Provide arguments.
-    common.InputTextArg.add_argument(parser, default=None)
-    common.FromFilesArg.add_argument(parser, default=[DEFAULT_TEXT_FILEPATH])
-    common.SynonymsCollectionFilepathArg.add_argument(parser, default=join(const.DATA_DIR, "synonyms.txt"))
-    common.EntitiesParserArg.add_argument(parser, default="bert-ontonotes")
-    common.RusVectoresEmbeddingFilepathArg.add_argument(parser, default=const.EMBEDDING_FILEPATH)
-    common.TermsPerContextArg.add_argument(parser, default=const.TERMS_PER_CONTEXT)
-    common.EntityFormatterTypesArg.add_argument(parser, default="hidden-simple-eng")
-    common.StemmerArg.add_argument(parser, default="mystem")
-    common.FramesColectionArg.add_argument(parser)
-
-    # Parsing arguments.
-    args = parser.parse_args()
-
-    synonyms_collection = read_synonyms_collection(
-        filepath=common.SynonymsCollectionFilepathArg.read_argument(args))
-
-    ppl = BasePipeline([
-        NetworkTextsSerializationPipelineItem(
-            terms_per_context=common.TermsPerContextArg.read_argument(args),
-            synonyms=synonyms_collection,
-            output_dir=const.OUTPUT_DIR,
-            entities_parser=common.EntitiesParserArg.read_argument(args),
-            embedding_path=common.RusVectoresEmbeddingFilepathArg.read_argument(args),
-            name_provider=ExperimentNameProvider(name="example", suffix="serialize"),
-            entity_fmt=create_entity_formatter(common.EntityFormatterTypesArg.read_argument(args)),
-            opin_annot=DefaultAnnotator(annot_algo=PairBasedAnnotationAlgorithm(
-                dist_in_terms_bound=None,
-                label_provider=ConstantLabelProvider(label_instance=NoLabel()))),
-            stemmer=common.StemmerArg.read_argument(args),
-            frames_collection=common.FramesColectionArg.read_argument(args),
-            data_folding=NoFolding(doc_ids_to_fold=[0], supported_data_types=[DataType.Test]))
-    ])
-
-    text_from_arg = common.InputTextArg.read_argument(args)
-    text_from_file = common.FromFilesArg.read_argument(args)
-
-    ppl.run(text_from_arg if text_from_arg is not None else text_from_file)
diff --git a/examples/train_bert.py b/examples/train_bert.py
index 916ee68..c4f3081 100644
--- a/examples/train_bert.py
+++ b/examples/train_bert.py
@@ -2,8 +2,8 @@
 from os.path import join
 
 from arekit.common.pipeline.base import BasePipeline
-from arelight.pipelines.train_bert import BertFinetunePipelineItem
 
+from arelight.pipelines.items.train_bert import BertFinetunePipelineItem
 from examples.args import train, common, const
 
 if __name__ == '__main__':
@@ -18,7 +18,8 @@
     common.BertCheckpointFilepathArg.add_argument(parser, default=const.BERT_CKPT_PATH)
     common.BertVocabFilepathArg.add_argument(parser, default=const.BERT_VOCAB_PATH)
     common.BertSaveFilepathArg.add_argument(parser, default=join(const.BERT_TARGET_DIR, const.BERT_DEFAULT_STATE_NAME))
-    common.InputSamplesFilepath.add_argument(parser, default=join(const.OUTPUT_DIR, join("rsr-v1_1-fx-nobalance-tpc50-bert_3l", "sample-train-0.tsv.gz")))
+    common.InputSamplesFilepath.add_argument(parser, default=join(
+        const.OUTPUT_DIR, join("rsr-v1_1-fx-nobalance-tpc50-bert_3l", "sample-train-0.tsv.gz")))
     train.LearningRateArg.add_argument(parser, default=2e-5)
     train.EpochsCountArg.add_argument(parser, default=4)
     train.BatchSizeArg.add_argument(parser, default=6)
@@ -28,16 +29,17 @@
     args = parser.parse_args()
 
     # Compose pipeline item.
-    ppl = BasePipeline([
+    pipeline = BasePipeline([
         BertFinetunePipelineItem(bert_config_file=common.BertConfigFilepathArg.read_argument(args),
                                  model_checkpoint_path=common.BertCheckpointFilepathArg.read_argument(args),
                                  vocab_filepath=common.BertVocabFilepathArg.read_argument(args),
                                  do_lowercase=train.DoLowercaseArg.read_argument(args),
                                  max_seq_length=common.TokensPerContextArg.read_argument(args),
                                  learning_rate=train.LearningRateArg.read_argument(args),
-                                 save_path=common.BertSaveFilepathArg.read_argument(args))
+                                 save_path=common.BertSaveFilepathArg.read_argument(args),
+                                 labels_count=3)
     ])
 
-    ppl.run(common.InputSamplesFilepath.read_argument(args),
-            params_dict={"epochs_count": train.EpochsCountArg.read_argument(args),
-                         "batch_size": train.BatchSizeArg.read_argument(args)})
+    pipeline.run(common.InputSamplesFilepath.read_argument(args),
+                 params_dict={"epochs_count": train.EpochsCountArg.read_argument(args),
+                              "batch_size": train.BatchSizeArg.read_argument(args)})
diff --git a/examples/train_nn.py b/examples/train_nn.py
new file mode 100644
index 0000000..19a58a4
--- /dev/null
+++ b/examples/train_nn.py
@@ -0,0 +1,49 @@
+import argparse
+
+from examples.args import const, train
+from arekit.contrib.networks.enum_input_types import ModelInputType
+from arekit.contrib.networks.enum_name_types import ModelNames
+
+from examples.args import common
+
+if __name__ == '__main__':
+
+    parser = argparse.ArgumentParser(description="Training script for obtaining Tensorflow based states, "
+                                                 "based on the RuSentRel and RuAttitudes datasets (optionally)")
+
+    # Composing cmd arguments.
+    common.LabelsCountArg.add_argument(parser, default=3)
+    common.TermsPerContextArg.add_argument(parser, default=const.TERMS_PER_CONTEXT)
+    common.DistanceInTermsBetweenAttitudeEndsArg.add_argument(parser, default=None)
+    common.ModelNameArg.add_argument(parser, default=ModelNames.PCNN.value)
+    common.VocabFilepathArg.add_argument(parser, default=None)
+    common.EmbeddingMatrixFilepathArg.add_argument(parser, default=None)
+    common.ModelLoadDirArg.add_argument(parser, default=None)
+    train.ModelInputTypeArg.add_argument(parser, default=ModelInputType.SingleInstance)
+    train.BagsPerMinibatchArg.add_argument(parser, default=const.BAGS_PER_MINIBATCH)
+    train.DropoutKeepProbArg.add_argument(parser, default=0.5)
+    train.LearningRateArg.add_argument(parser, default=0.1)
+    train.EpochsCountArg.add_argument(parser, default=150)
+
+    # Parsing arguments.
+    args = parser.parse_args()
+
+    # Reading arguments.
+    labels_count = common.LabelsCountArg.read_argument(args)
+    model_name = common.ModelNameArg.read_argument(args)
+    embedding_matrix_filepath = common.EmbeddingMatrixFilepathArg.read_argument(args)
+    vocab_filepath = common.VocabFilepathArg.read_argument(args)
+    terms_per_context = common.TermsPerContextArg.read_argument(args)
+    dist_in_terms_between_attitude_ends = common.DistanceInTermsBetweenAttitudeEndsArg.read_argument(args)
+    model_load_dir = common.ModelLoadDirArg.read_argument(args)
+    model_input_type = train.ModelInputTypeArg.read_argument(args)
+    bags_per_minibatch = train.BagsPerMinibatchArg.read_argument(args)
+    dropout_keep_prob = train.DropoutKeepProbArg.read_argument(args)
+    learning_rate = train.LearningRateArg.read_argument(args)
+    epochs_count = train.EpochsCountArg.read_argument(args)
+
+    # TODO. Adopt code from the NIVTS Project.
+    # TODO.
+    # TODO.
+    # TODO.
+    # TODO.
diff --git a/examples/train_nn_on_rusentrel.py b/examples/train_nn_on_rusentrel.py
deleted file mode 100644
index 3752ddd..0000000
--- a/examples/train_nn_on_rusentrel.py
+++ /dev/null
@@ -1,168 +0,0 @@
-import argparse
-
-from arelight.network.nn.common import create_bags_collection_type, create_full_model_name, create_network_model_io
-
-from examples.args import const, train
-from examples.rusentrel.common import Common
-from examples.args.const import NEURAL_NETWORKS_TARGET_DIR, BAG_SIZE
-from examples.rusentrel.config_setups import optionally_modify_config_for_experiment, modify_config_for_model
-from examples.rusentrel.exp_io import CustomRuSentRelNetworkExperimentIO
-
-from arekit.common.experiment.api.ctx_training import ExperimentTrainingContext
-from arekit.common.experiment.engine import ExperimentEngine
-from arekit.common.experiment.name_provider import ExperimentNameProvider
-from arekit.common.folding.types import FoldingType
-from arekit.contrib.experiment_rusentrel.types import ExperimentTypes
-from arekit.contrib.networks.context.configurations.base.base import DefaultNetworkConfig
-from arekit.contrib.networks.core.callback.hidden import HiddenStatesWriterCallback
-from arekit.contrib.networks.core.callback.hidden_input import InputHiddenStatesWriterCallback
-from arekit.contrib.networks.core.callback.stat import TrainingStatProviderCallback
-from arekit.contrib.networks.core.callback.train_limiter import TrainingLimiterCallback
-from arekit.contrib.networks.enum_input_types import ModelInputType
-from arekit.contrib.networks.enum_name_types import ModelNames
-from arekit.contrib.networks.factory import create_network_and_network_config_funcs
-from arekit.contrib.networks.np_utils.writer import NpzDataWriter
-from arekit.contrib.networks.handlers.training import NetworksTrainingIterationHandler
-from arekit.contrib.source.rusentrel.io_utils import RuSentRelVersions
-from arekit.processing.languages.ru.pos_service import PartOfSpeechTypesService
-
-from examples.args import common
-from examples.utils import create_labels_scaler
-
-if __name__ == '__main__':
-
-    parser = argparse.ArgumentParser(description="Training script for obtaining Tensorflow based states, "
-                                                 "based on the RuSentRel and RuAttitudes datasets (optionally)")
-
-    # Composing cmd arguments.
-    common.LabelsCountArg.add_argument(parser, default=3)
-    common.TermsPerContextArg.add_argument(parser, default=const.TERMS_PER_CONTEXT)
-    common.DistanceInTermsBetweenAttitudeEndsArg.add_argument(parser, default=None)
-    common.ModelNameArg.add_argument(parser, default=ModelNames.PCNN.value)
-    common.VocabFilepathArg.add_argument(parser, default=None)
-    common.EmbeddingMatrixFilepathArg.add_argument(parser, default=None)
-    common.ModelLoadDirArg.add_argument(parser, default=None)
-    train.ModelInputTypeArg.add_argument(parser, default=ModelInputType.SingleInstance)
-    train.BagsPerMinibatchArg.add_argument(parser, default=const.BAGS_PER_MINIBATCH)
-    train.DropoutKeepProbArg.add_argument(parser, default=0.5)
-    train.LearningRateArg.add_argument(parser, default=0.1)
-    train.EpochsCountArg.add_argument(parser, default=150)
-
-    # Parsing arguments.
-    args = parser.parse_args()
-
-    # Reading arguments.
-    labels_count = common.LabelsCountArg.read_argument(args)
-    model_name = common.ModelNameArg.read_argument(args)
-    embedding_matrix_filepath = common.EmbeddingMatrixFilepathArg.read_argument(args)
-    vocab_filepath = common.VocabFilepathArg.read_argument(args)
-    terms_per_context = common.TermsPerContextArg.read_argument(args)
-    dist_in_terms_between_attitude_ends = common.DistanceInTermsBetweenAttitudeEndsArg.read_argument(args)
-    model_load_dir = common.ModelLoadDirArg.read_argument(args)
-    model_input_type = train.ModelInputTypeArg.read_argument(args)
-    bags_per_minibatch = train.BagsPerMinibatchArg.read_argument(args)
-    dropout_keep_prob = train.DropoutKeepProbArg.read_argument(args)
-    learning_rate = train.LearningRateArg.read_argument(args)
-    epochs_count = train.EpochsCountArg.read_argument(args)
-
-    # Utilize predefined versions and folding format.
-    exp_type = ExperimentTypes.RuSentRel
-    rusentrel_version = RuSentRelVersions.V11
-    folding_type = FoldingType.Fixed
-    model_target_dir = NEURAL_NETWORKS_TARGET_DIR
-
-    # Init handler.
-    bags_collection_type = create_bags_collection_type(model_input_type=model_input_type)
-    network_func, network_config_func = create_network_and_network_config_funcs(
-        model_name=model_name,
-        model_input_type=model_input_type)
-
-    labels_scaler = create_labels_scaler(labels_count)
-
-    exp_name = Common.create_exp_name(rusentrel_version=rusentrel_version,
-                                      ra_version=None,
-                                      folding_type=folding_type)
-
-    extra_name_suffix = Common.create_exp_name_suffix(
-        use_balancing=True,
-        terms_per_context=terms_per_context,
-        dist_in_terms_between_att_ends=dist_in_terms_between_attitude_ends)
-
-    data_folding = Common.create_folding(
-        rusentrel_version=rusentrel_version,
-        ruattitudes_version=None,
-        doc_id_func=lambda doc_id: Common.ra_doc_id_func(doc_id=doc_id))
-
-    # Creating experiment
-    exp_ctx = ExperimentTrainingContext(labels_count=labels_scaler.LabelsCount,
-                                        name_provider=ExperimentNameProvider(name=exp_name, suffix=extra_name_suffix),
-                                        data_folding=data_folding)
-
-    exp_io = CustomRuSentRelNetworkExperimentIO(exp_ctx)
-
-    full_model_name = create_full_model_name(model_name=model_name,
-                                             input_type=model_input_type)
-
-    model_io = create_network_model_io(full_model_name=full_model_name,
-                                       source_dir=model_load_dir,
-                                       target_dir=model_target_dir,
-                                       embedding_filepath=embedding_matrix_filepath,
-                                       vocab_filepath=vocab_filepath,
-                                       model_name_tag=u'')
-
-    # Setup model io.
-    exp_ctx.set_model_io(model_io)
-
-    ###################
-    # Initialize config
-    ###################
-    config = network_config_func()
-
-    assert(isinstance(config, DefaultNetworkConfig))
-
-    # Default settings, applied from cmd arguments.
-    config.modify_classes_count(value=labels_count)
-    config.modify_learning_rate(learning_rate)
-    config.modify_use_class_weights(True)
-    config.modify_dropout_keep_prob(dropout_keep_prob)
-    config.modify_bag_size(BAG_SIZE)
-    config.modify_bags_per_minibatch(bags_per_minibatch)
-    config.modify_embedding_dropout_keep_prob(1.0)
-    config.modify_terms_per_context(terms_per_context)
-    config.modify_use_entity_types_in_embedding(False)
-    config.set_pos_count(PartOfSpeechTypesService.get_mystem_pos_count())
-
-    # Modify config parameters. This may affect
-    # the settings, already applied above!
-    optionally_modify_config_for_experiment(exp_type=exp_type,
-                                            model_input_type=model_input_type,
-                                            config=config)
-
-    # Modify config parameters. This may affect
-    # the settings, already applied above!
-    modify_config_for_model(model_name=model_name,
-                            model_input_type=model_input_type,
-                            config=config)
-
-    data_writer = NpzDataWriter()
-
-    nework_callbacks = [
-        TrainingLimiterCallback(train_acc_limit=0.99),
-        TrainingStatProviderCallback(),
-        HiddenStatesWriterCallback(log_dir=model_target_dir, writer=data_writer),
-        InputHiddenStatesWriterCallback(log_dir=model_target_dir, writer=data_writer)
-    ]
-
-    training_handler = NetworksTrainingIterationHandler(
-        load_model=model_load_dir is not None,
-        exp_ctx=exp_ctx,
-        exp_io=exp_io,
-        create_network_func=network_func,
-        config=config,
-        bags_collection_type=bags_collection_type,
-        network_callbacks=nework_callbacks,
-        training_epochs=epochs_count)
-
-    engine = ExperimentEngine(exp_ctx.DataFolding)
-
-    engine.run(handlers=[training_handler])
diff --git a/examples/utils.py b/examples/utils.py
index 87d705d..88b1fe4 100644
--- a/examples/utils.py
+++ b/examples/utils.py
@@ -1,15 +1,15 @@
-from arekit.contrib.experiment_rusentrel.labels.scalers.three import ThreeLabelScaler
-from arekit.contrib.experiment_rusentrel.labels.scalers.two import TwoLabelScaler
-from arekit.contrib.experiment_rusentrel.synonyms.collection import StemmerBasedSynonymCollection
-from arekit.contrib.source.rusentrel.utils import iter_synonym_groups
-from arekit.processing.lemmatization.mystem import MystemWrapper
+from enum import Enum
+
+from arekit.contrib.source.synonyms.utils import iter_synonym_groups
+from arekit.contrib.utils.processing.lemmatization.mystem import MystemWrapper
+from arekit.contrib.utils.synonyms.stemmer_based import StemmerBasedSynonymCollection
+
+from arelight.pipelines.demo.labels.scalers import ThreeLabelScaler
 
 
 def create_labels_scaler(labels_count):
     assert (isinstance(labels_count, int))
 
-    if labels_count == 2:
-        return TwoLabelScaler()
     if labels_count == 3:
         return ThreeLabelScaler()
 
@@ -28,3 +28,35 @@ def __iter_groups(filepath):
         stemmer=MystemWrapper(),
         is_read_only=False,
         debug=False)
+
+
+class EnumConversionService(object):
+
+    _data = None
+
+    @classmethod
+    def is_supported(cls, name):
+        assert(isinstance(cls._data, dict))
+        return name in cls._data
+
+    @classmethod
+    def name_to_type(cls, name):
+        assert(isinstance(cls._data, dict))
+        assert(isinstance(name, str))
+        return cls._data[name]
+
+    @classmethod
+    def iter_names(cls):
+        assert(isinstance(cls._data, dict))
+        return iter(list(cls._data.keys()))
+
+    @classmethod
+    def type_to_name(cls, enum_type):
+        assert(isinstance(cls._data, dict))
+        assert(isinstance(enum_type, Enum))
+
+        for item_name, item_type in cls._data.items():
+            if item_type == enum_type:
+                return item_name
+
+        raise NotImplemented("Formatting type '{}' does not supported".format(enum_type))
diff --git a/setup.py b/setup.py
index 463f5d3..6249264 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@ def get_requirements(filenames):
 
 setup(
     name='arelight',
-    version='0.22.0',
+    version='0.22.1',
     description='About Mass-media text processing application for your '
                 'Relation Extraction task, powered by AREkit.',
     url='https://github.com/nicolay-r/ARElight',
diff --git a/update_arekit.sh b/update_arekit.sh
index 0740b83..8c2788d 100755
--- a/update_arekit.sh
+++ b/update_arekit.sh
@@ -1,2 +1,2 @@
-pip uninstall arekit
-pip install git+https://github.com/nicolay-r/AREkit@0.22.0-rc
+pip3 uninstall arekit
+pip3 install git+https://github.com/nicolay-r/AREkit@master --no-deps


Test patch:
diff --git a/test/data/sample-test-0.tsv.gz b/test/data/sample-test-0.tsv.gz
index ab24c76..2c925f6 100644
Binary files a/test/data/sample-test-0.tsv.gz and b/test/data/sample-test-0.tsv.gz differ
diff --git a/test/test_bert_ontonotes_ner.py b/test/test_bert_ontonotes_ner.py
index 8fde7fb..b67c18a 100644
--- a/test/test_bert_ontonotes_ner.py
+++ b/test/test_bert_ontonotes_ner.py
@@ -1,7 +1,7 @@
 import unittest
 
-from arekit.processing.entities.obj_desc import NerObjectDescriptor
-from arelight.text.ner_ontonotes import BertOntonotesNER
+from arelight.ner.obj_desc import NerObjectDescriptor
+from arelight.ner.ontonotes import BertOntonotesNER
 
 
 class BertOntonotesTest(unittest.TestCase):
diff --git a/test/test_bert_ontonotes_ner_pipeline_item.py b/test/test_bert_ontonotes_ner_pipeline_item.py
index 620c8bd..a313c30 100644
--- a/test/test_bert_ontonotes_ner_pipeline_item.py
+++ b/test/test_bert_ontonotes_ner_pipeline_item.py
@@ -4,8 +4,9 @@
 from arekit.common.news.parser import NewsParser
 from arekit.common.news.sentence import BaseNewsSentence
 from arekit.common.text.parser import BaseTextParser
-from arekit.processing.text.pipeline_terms_splitter import TermsSplitterParser
-from arelight.text.pipeline_entities_bert_ontonotes import BertOntonotesNERPipelineItem
+from arekit.contrib.utils.pipelines.items.text.terms_splitter import TermsSplitterParser
+
+from arelight.pipelines.items.entities_bert_ontonotes import BertOntonotesNERPipelineItem
 
 
 class BertOntonotesPipelineItemTest(unittest.TestCase):
diff --git a/test/test_bert_serialization.py b/test/test_bert_serialization.py
index 5d9a4ad..31ae6f2 100644
--- a/test/test_bert_serialization.py
+++ b/test/test_bert_serialization.py
@@ -1,37 +1,42 @@
 import unittest
+
+from arekit.contrib.utils.pipelines.items.sampling.bert import BertExperimentInputSerializerPipelineItem
+from ru_sent_tokenize import ru_sent_tokenize
 from os.path import dirname, join, realpath
 
-from arekit.common.experiment.annot.algo.pair_based import PairBasedAnnotationAlgorithm
-from arekit.common.experiment.annot.default import DefaultAnnotator
-from arekit.common.experiment.api.base import BaseExperiment
 from arekit.common.experiment.data_type import DataType
-from arekit.common.experiment.engine import ExperimentEngine
-from arekit.common.experiment.name_provider import ExperimentNameProvider
 from arekit.common.folding.nofold import NoFolding
 from arekit.common.labels.base import NoLabel
-from arekit.common.labels.provider.constant import ConstantLabelProvider
 from arekit.common.labels.scaler.single import SingleLabelScaler
 from arekit.common.labels.str_fmt import StringLabelsFormatter
 from arekit.common.news.base import News
 from arekit.common.news.entities_grouping import EntitiesGroupingPipelineItem
 from arekit.common.news.sentence import BaseNewsSentence
+from arekit.common.pipeline.base import BasePipeline
+from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
 from arekit.common.text.parser import BaseTextParser
-from arekit.contrib.bert.handlers.serializer import BertExperimentInputSerializerIterationHandler
-from arekit.contrib.bert.samplers.types import BertSampleProviderTypes
-from arekit.contrib.experiment_rusentrel.entities.str_simple_sharp_prefixed_fmt import \
-    SharpPrefixedEntitiesSimpleFormatter
-from arekit.contrib.experiment_rusentrel.synonyms.collection import StemmerBasedSynonymCollection
-from arekit.contrib.source.rusentrel.utils import iter_synonym_groups
-from arekit.processing.lemmatization.mystem import MystemWrapper
-from arekit.processing.text.pipeline_terms_splitter import TermsSplitterParser
-from ru_sent_tokenize import ru_sent_tokenize
+from arekit.contrib.utils.io_utils.samples import SamplesIO
+from arekit.contrib.utils.pipelines.items.text.terms_splitter import TermsSplitterParser
+from arekit.contrib.utils.processing.lemmatization.mystem import MystemWrapper
+from arekit.contrib.utils.synonyms.stemmer_based import StemmerBasedSynonymCollection
+from arekit.contrib.utils.entities.formatters.str_simple_sharp_prefixed_fmt import SharpPrefixedEntitiesSimpleFormatter
+from arekit.contrib.source.synonyms.utils import iter_synonym_groups
+
+from arelight.doc_ops import InMemoryDocOperations
+from arelight.pipelines.annot_nolabel import create_neutral_annotation_pipeline
+from arelight.pipelines.items.entities_bert_ontonotes import BertOntonotesNERPipelineItem
+from arelight.pipelines.items.utils import input_to_docs
+from arelight.samplers.bert import create_bert_sample_provider
+from arelight.samplers.types import BertSampleProviderTypes
+
+
+class EntityFilter(object):
 
-from arelight.exp.doc_ops import CustomDocOperations
-from arelight.exp.exp_io import InferIOUtils
-from arelight.exp.opin_ops import CustomOpinionOperations
-from arelight.network.bert.ctx import BertSerializationContext
-from arelight.pipelines.utils import input_to_docs
-from arelight.text.pipeline_entities_bert_ontonotes import BertOntonotesNERPipelineItem
+    def __init__(self):
+        pass
+
+    def is_ignored(self, entity, e_type):
+        raise NotImplementedError()
 
 
 class BertTestSerialization(unittest.TestCase):
@@ -44,12 +49,6 @@ class BertTestSerialization(unittest.TestCase):
     ORIGIN_DATA_DIR = join(current_dir, "../data")
     TEST_DATA_DIR = join(current_dir, "data")
 
-    @staticmethod
-    def get_synonym_group_index(s, value):
-        if not s.contains_synonym_value(value):
-            s.add_synonym_value(value)
-        return s.get_synonym_group_index(value)
-
     @staticmethod
     def input_to_docs(texts):
         docs = []
@@ -91,58 +90,53 @@ def test(self):
         text_parser = BaseTextParser(pipeline=[
             TermsSplitterParser(),
             BertOntonotesNERPipelineItem(lambda s_obj: s_obj.ObjectType in ["ORG", "PERSON", "LOC", "GPE"]),
-            EntitiesGroupingPipelineItem(lambda value: self.get_synonym_group_index(synonyms, value))
+            EntitiesGroupingPipelineItem(lambda value:
+                SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
+                    synonyms=synonyms, value=value))
         ])
 
-        # Declaring algo.
-        algo = PairBasedAnnotationAlgorithm(
-            label_provider=ConstantLabelProvider(label_instance=NoLabel()),
-            dist_in_terms_bound=None)
+        # Single label scaler.
+        single_label_scaler = SingleLabelScaler(NoLabel())
 
         # Declare folding and experiment context.
-        no_folding = NoFolding(doc_ids_to_fold=list(range(len(texts))),
-                               supported_data_types=[DataType.Test])
-        exp_ctx = BertSerializationContext(
-            label_scaler=SingleLabelScaler(NoLabel()),
-            annotator=DefaultAnnotator(algo),
-            terms_per_context=50,
-            str_entity_formatter=SharpPrefixedEntitiesSimpleFormatter(),
-            name_provider=ExperimentNameProvider(name="example-bert", suffix="serialize"),
-            data_folding=no_folding)
+        no_folding = NoFolding(doc_ids=list(range(len(texts))), supported_data_type=DataType.Test)
 
         # Composing labels formatter and experiment preparation.
         labels_fmt = StringLabelsFormatter(stol={"neu": NoLabel})
-        exp_io = InferIOUtils(exp_ctx=exp_ctx, output_dir=self.TEST_DATA_DIR)
-        doc_ops = CustomDocOperations(exp_ctx, text_parser=text_parser)
-        opin_ops = CustomOpinionOperations(
-            labels_formatter=labels_fmt,
-            exp_io=exp_io,
-            synonyms=synonyms,
-            neutral_labels_fmt=labels_fmt)
-
-        exp = BaseExperiment(exp_io=exp_io, exp_ctx=exp_ctx, doc_ops=doc_ops, opin_ops=opin_ops)
-
-        handler = BertExperimentInputSerializerIterationHandler(
-            exp_io=exp_io,
-            exp_ctx=exp_ctx,
-            doc_ops=doc_ops,
-            opin_ops=exp.OpinionOperations,
-            ###
-            sample_provider_type=BertSampleProviderTypes.NLI_M,     # TODO. Part of TEXT_B
-            sample_labels_fmt=labels_fmt,                           # TODO. Part of TEXT_B
-            ###
-            annot_labels_fmt=labels_fmt,                            # TODO. To be removed in further.
-            entity_formatter=exp_ctx.StringEntityFormatter,
-            value_to_group_id_func=synonyms.get_synonym_group_index,
-            balance_train_samples=True)
-
-        # Initilize documents.
-        docs = input_to_docs(texts)
-        doc_ops.set_docs(docs)
-
-        # Run.
-        engine = ExperimentEngine(exp_ctx.DataFolding)  # Present folding limitation.
-        engine.run([handler])
+        doc_ops = InMemoryDocOperations(docs=input_to_docs(texts))
+
+        rows_provider = create_bert_sample_provider(
+            label_scaler=single_label_scaler,
+            provider_type=BertSampleProviderTypes.NLI_M,
+            text_b_labels_fmt=labels_fmt,
+            entity_formatter=SharpPrefixedEntitiesSimpleFormatter())
+
+        pipeline = BasePipeline([
+            BertExperimentInputSerializerPipelineItem(
+                sample_rows_provider=rows_provider,
+                samples_io=SamplesIO(target_dir=self.TEST_DATA_DIR),
+                save_labels_func=lambda data_type: data_type != DataType.Test,
+                balance_func=lambda data_type: data_type == DataType.Train)
+        ])
+
+        synonyms = StemmerBasedSynonymCollection(iter_group_values_lists=[],
+                                                 stemmer=MystemWrapper(),
+                                                 is_read_only=False,
+                                                 debug=False)
+
+        # Initialize data processing pipeline.
+        test_pipeline = create_neutral_annotation_pipeline(synonyms=synonyms,
+                                                           dist_in_terms_bound=50,
+                                                           dist_in_sentences=0,
+                                                           doc_ops=doc_ops,
+                                                           text_parser=text_parser,
+                                                           terms_per_context=50)
+
+        pipeline.run(input_data=None,
+                     params_dict={
+                         "data_folding": no_folding,
+                         "data_type_pipelines": {DataType.Test: test_pipeline}
+                     })
 
 
 if __name__ == '__main__':
diff --git a/test/test_brat_backend.py b/test/test_brat_backend.py
index c5c898e..20a3c0a 100644
--- a/test/test_brat_backend.py
+++ b/test/test_brat_backend.py
@@ -2,10 +2,9 @@
 import unittest
 from os.path import join, dirname, realpath
 
-from arekit.contrib.experiment_rusentrel.labels.scalers.three import ThreeLabelScaler
-from arekit.contrib.experiment_rusentrel.labels.types import ExperimentNegativeLabel, ExperimentPositiveLabel
-
 from arelight.brat_backend import BratBackend
+from arelight.pipelines.demo.labels.base import PositiveLabel, NegativeLabel
+from arelight.pipelines.demo.labels.scalers import ThreeLabelScaler
 
 
 class TestBratEmbedding(unittest.TestCase):
@@ -33,8 +32,8 @@ def __create_template(self, result_data_filepath, samples_data_filepath, labels_
         contents = brat_be.to_data(
             result_data_filepath=result_data_filepath,
             samples_data_filepath=samples_data_filepath,
-            label_to_rel={str(labels_scaler.label_to_uint(ExperimentPositiveLabel())): "POS",
-                          str(labels_scaler.label_to_uint(ExperimentNegativeLabel())): "NEG"},
+            label_to_rel={str(labels_scaler.label_to_uint(PositiveLabel())): "POS",
+                          str(labels_scaler.label_to_uint(NegativeLabel())): "NEG"},
             obj_color_types={"ORG": '#7fa2ff',
                              "GPE": "#7fa200",
                              "PER": "#7f00ff",
diff --git a/test/test_demo.py b/test/test_demo.py
index cb68de4..d965b77 100644
--- a/test/test_demo.py
+++ b/test/test_demo.py
@@ -2,14 +2,37 @@
 import unittest
 from os.path import dirname, realpath, join
 
-from arekit.contrib.experiment_rusentrel.labels.formatters.rusentiframes import ExperimentRuSentiFramesLabelsFormatter
+from arekit.common.experiment.data_type import DataType
+from arekit.common.folding.nofold import NoFolding
+from arekit.common.news.entities_grouping import EntitiesGroupingPipelineItem
+from arekit.common.synonyms.grouping import SynonymsCollectionValuesGroupingProviders
+from arekit.common.text.parser import BaseTextParser
 from arekit.contrib.networks.enum_input_types import ModelInputType
 from arekit.contrib.networks.enum_name_types import ModelNames
 from arekit.contrib.source.rusentiframes.collection import RuSentiFramesCollection
+from arekit.contrib.source.rusentiframes.labels_fmt import RuSentiFramesLabelsFormatter, \
+    RuSentiFramesEffectLabelsFormatter
 from arekit.contrib.source.rusentiframes.types import RuSentiFramesVersions
+from arekit.contrib.utils.entities.formatters.str_simple_fmt import StringEntitiesSimpleFormatter
+from arekit.contrib.utils.entities.formatters.str_simple_sharp_prefixed_fmt import SharpPrefixedEntitiesSimpleFormatter
+from arekit.contrib.utils.pipelines.items.text.frames import FrameVariantsParser
+from arekit.contrib.utils.pipelines.items.text.frames_lemmatized import LemmasBasedFrameVariantsParser
+from arekit.contrib.utils.pipelines.items.text.frames_negation import FrameVariantsSentimentNegation
+from arekit.contrib.utils.pipelines.items.text.terms_splitter import TermsSplitterParser
+from arekit.contrib.utils.pipelines.items.text.tokenizer import DefaultTextTokenizer
+from arekit.contrib.utils.processing.lemmatization.mystem import MystemWrapper
+
+from arelight.doc_ops import InMemoryDocOperations
+from arelight.network.nn.common import create_and_fill_variant_collection
+from arelight.pipelines.annot_nolabel import create_neutral_annotation_pipeline
+from arelight.pipelines.demo.infer_bert_rus import demo_infer_texts_bert_pipeline
+from arelight.pipelines.demo.infer_nn_rus import demo_infer_texts_tensorflow_nn_pipeline
+from arelight.pipelines.demo.labels.base import NegativeLabel, PositiveLabel
+from arelight.pipelines.demo.labels.scalers import ThreeLabelScaler
+from arelight.pipelines.demo.utils import read_synonyms_collection
+from arelight.pipelines.items.entities_bert_ontonotes import BertOntonotesNERPipelineItem
+from arelight.pipelines.items.utils import input_to_docs
 
-from arelight.demo.infer_bert_rus import demo_infer_texts_bert_pipeline
-from arelight.demo.infer_nn_rus import demo_infer_texts_tensorflow_nn_pipeline
 from examples.args import const
 
 
@@ -39,19 +62,56 @@ def __prepare_template(data, text, template_filepath, brat_url):
     def test_demo_rus_nn(self):
         frames_collection = RuSentiFramesCollection.read_collection(
             version=RuSentiFramesVersions.V20,
-            labels_fmt=ExperimentRuSentiFramesLabelsFormatter())
+            labels_fmt=RuSentiFramesLabelsFormatter(
+                pos_label_type=PositiveLabel, neg_label_type=NegativeLabel),
+            effect_labels_fmt=RuSentiFramesEffectLabelsFormatter(
+                pos_label_type=PositiveLabel, neg_label_type=NegativeLabel))
 
-        ppl = demo_infer_texts_tensorflow_nn_pipeline(
+        demo_pipeline = demo_infer_texts_tensorflow_nn_pipeline(
             texts_count=1,
             output_dir=".",
             model_name=ModelNames.PCNN,
-            synonyms_filepath=join(TestDemo.ORIGIN_DATA_DIR, "synonyms.txt"),
+            entity_fmt=StringEntitiesSimpleFormatter(),
             model_load_dir=const.NEURAL_NETWORKS_TARGET_DIR,
-            embedding_filepath=const.EMBEDDING_FILEPATH,
             model_input_type=ModelInputType.SingleInstance,
             frames_collection=frames_collection)
 
-        contents = ppl.run([self.text])
+        stemmer = MystemWrapper()
+
+        # Initialize text parser with the related dependencies.
+        frame_variants_collection = create_and_fill_variant_collection(frames_collection)
+        text_parser = BaseTextParser(pipeline=[
+            TermsSplitterParser(),
+            BertOntonotesNERPipelineItem(lambda s_obj: s_obj.ObjectType in ["ORG", "PERSON", "LOC", "GPE"]),
+            EntitiesGroupingPipelineItem(
+                lambda value: SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
+                    synonyms, value)),
+            DefaultTextTokenizer(keep_tokens=True),
+            FrameVariantsParser(frame_variants=frame_variants_collection),
+            LemmasBasedFrameVariantsParser(save_lemmas=False,
+                                           stemmer=stemmer,
+                                           frame_variants=frame_variants_collection),
+            FrameVariantsSentimentNegation()])
+
+        synonyms = read_synonyms_collection(synonyms_filepath=join(self.ORIGIN_DATA_DIR, "synonyms.txt"),
+                                            stemmer=stemmer)
+
+        single_doc = [self.text.strip()]
+        doc_ops = InMemoryDocOperations(docs=input_to_docs(single_doc))
+
+        # Initialize data processing pipeline.
+        data_pipeline = create_neutral_annotation_pipeline(synonyms=synonyms,
+                                                           dist_in_terms_bound=50,
+                                                           terms_per_context=50,
+                                                           doc_ops=doc_ops,
+                                                           text_parser=text_parser,
+                                                           dist_in_sentences=0)
+
+        contents = demo_pipeline.run(None, {
+            "template_filepath": join(const.DATA_DIR, "brat_template.html"),
+            "data_folding": NoFolding(doc_ids=[0], supported_data_type=DataType.Test),
+            "data_type_pipelines": {DataType.Test: data_pipeline}
+        })
 
         template = TestDemo.__prepare_template(
             data=contents, text=self.text,
@@ -67,15 +127,40 @@ def test_demo_rus_bert(self):
         state_name = "ra-20-srubert-large-neut-nli-pretrained-3l"
         finetuned_state_name = "ra-20-srubert-large-neut-nli-pretrained-3l-finetuned"
 
-        ppl = demo_infer_texts_bert_pipeline(
+        demo_pipeline = demo_infer_texts_bert_pipeline(
             texts_count=1,
             output_dir=".",
+            labels_scaler=ThreeLabelScaler(),
+            entity_fmt=SharpPrefixedEntitiesSimpleFormatter(),
             bert_vocab_path=join(model_dir, state_name, "vocab.txt"),
             bert_config_path=join(model_dir, state_name, "bert_config.json"),
-            bert_finetuned_ckpt_path=join(model_dir, finetuned_state_name, state_name),
-            synonyms_filepath=join(TestDemo.ORIGIN_DATA_DIR, "synonyms.txt"))
-
-        contents = ppl.run([self.text])
+            bert_finetuned_ckpt_path=join(model_dir, finetuned_state_name, state_name))
+
+        single_doc = [self.text.strip()]
+        doc_ops = InMemoryDocOperations(docs=input_to_docs(single_doc))
+
+        synonyms = read_synonyms_collection(synonyms_filepath=join(self.ORIGIN_DATA_DIR, "synonyms.txt"),
+                                            stemmer=MystemWrapper())
+
+        text_parser = BaseTextParser(pipeline=[
+            TermsSplitterParser(),
+            BertOntonotesNERPipelineItem(lambda s_obj: s_obj.ObjectType in ["ORG", "PERSON", "LOC", "GPE"]),
+            EntitiesGroupingPipelineItem(
+                lambda value: SynonymsCollectionValuesGroupingProviders.provide_existed_or_register_missed_value(
+                    synonyms=synonyms, value=value))
+        ])
+
+        data_pipeline = create_neutral_annotation_pipeline(synonyms=synonyms,
+                                                           terms_per_context=50,
+                                                           dist_in_terms_bound=50,
+                                                           doc_ops=doc_ops,
+                                                           text_parser=text_parser)
+
+        contents = demo_pipeline.run(None, {
+            "template_filepath": join(const.DATA_DIR, "brat_template.html"),
+            "data_folding": NoFolding(doc_ids_to_fold=[0], supported_data_types=[DataType.Test]),
+            "data_type_pipelines": {DataType.Test: data_pipeline}
+        })
 
         template = TestDemo.__prepare_template(
             data=contents, text=self.text,