bert-as-service | length sentence to a fixed-length vector | Natural Language Processing library

 by   hanxiao Python Version: v1.8.1 License: MIT

kandi X-RAY | bert-as-service Summary

kandi X-RAY | bert-as-service Summary

bert-as-service is a Python library typically used in Telecommunications, Media, Media, Entertainment, Artificial Intelligence, Natural Language Processing, Deep Learning, Tensorflow, Bert, Neural Network, Transformer applications. bert-as-service has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. However bert-as-service build file is not available. You can install using 'pip install bert-as-service' or download it from GitHub, PyPI.

BERT is a NLP model developed by Google for pre-training language representations. It leverages an enormous amount of plain text data publicly available on the web and is trained in an unsupervised manner. Pre-training a BERT model is a fairly expensive yet one-time procedure for each language. Fortunately, Google released several pre-trained models where you can download from here. Sentence Encoding/Embedding is a upstream task required in many NLP applications, e.g. sentiment analysis, text classification. The goal is to represent a variable length sentence into a fixed length vector, e.g. hello world to [0.1, 0.3, 0.9]. Each element of the vector should "encode" some semantics of the original sentence. Finally, bert-as-service uses BERT as a sentence encoder and hosts it as a service via ZeroMQ, allowing you to map sentences into fixed-length representations in just two lines of code.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              bert-as-service has a medium active ecosystem.
              It has 9373 star(s) with 1823 fork(s). There are 202 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 240 open issues and 251 have been closed. On average issues are closed in 62 days. There are 10 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of bert-as-service is v1.8.1

            kandi-Quality Quality

              bert-as-service has 0 bugs and 0 code smells.

            kandi-Security Security

              bert-as-service has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              bert-as-service code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              bert-as-service is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              bert-as-service releases are available to install and integrate.
              Deployable package is available in PyPI.
              bert-as-service has no build file. You will be need to create the build yourself to build the component from source.
              Installation instructions, examples and code snippets are available.
              bert-as-service saves you 1240 person hours of effort in developing the same functionality from scratch.
              It has 2790 lines of code, 182 functions and 33 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed bert-as-service and discovered the below as its top functions. This is intended to give you an instant insight into bert-as-service implemented functionality, and help decide if they suit your requirements.
            • Converts an input layer to an output layer .
            • Tries to optimize the graph .
            • Creates a transformer model for the input Tensor .
            • Post - processor post - processing .
            • the main loop .
            • This method initializes the Argus Argument parser to be used to start the server .
            • Converts the Lst string to features .
            • Updates variables in the input graph
            • Encodes the given texts .
            • Creates an optimization for the given parameters .
            Get all kandi verified functions for this library.

            bert-as-service Key Features

            No Key Features are available at this moment for bert-as-service.

            bert-as-service Examples and Code Snippets

            bert-as-service,:book: Tutorial,Saving and loading with TFRecord data
            Pythondot img1Lines of Code : 38dot img1License : Permissive (MIT)
            copy iconCopy
            bc = BertClient()
            list_vec = bc.encode(lst_str)
            list_label = [0 for _ in lst_str]  # a dummy list of all-zero labels
            
            # write to tfrecord
            with tf.python_io.TFRecordWriter('tmp.tfrecord') as writer:
                def create_float_feature(values):
                    return  
            bert-as-service,:speech_balloon: FAQ
            Pythondot img2Lines of Code : 37dot img2License : Permissive (MIT)
            copy iconCopy
            bert-serving-start -pooling_layer -4 -3 -2 -1 -model_dir /tmp/english_L-12_H-768_A-12/
            
            bc.encode(['hey you', 'whats up?', '你好么?', '我 还 可以'])
            
            tokens: [CLS] hey you [SEP]
            input_ids: 101 13153 8357 102 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
            input_m  
            bert-as-service,:book: Tutorial,Using your own tokenizer
            Pythondot img3Lines of Code : 26dot img3License : Permissive (MIT)
            copy iconCopy
            texts = ['hello world!', 'good day']
            
            # a naive whitespace tokenizer
            texts2 = [s.split() for s in texts]
            
            vecs = bc.encode(texts2, is_tokenized=True)
            
            bc.encode(['hello world!', 'thisis it'], show_tokens=True)
            
            (array([[[ 0.        , -0.        ,  0.  
            How to cluster similar sentences using BERT
            Pythondot img4Lines of Code : 9dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            pip install bert-serving-server  # server
            pip install bert-serving-client  # client, independent of `bert-serving-server`
            
            bert-serving-start -model_dir /your_model_directory/ -num_worker=4 
            

            Community Discussions

            Trending Discussions on bert-as-service

            QUESTION

            BERT sentence embeddings from transformers
            Asked 2020-Oct-07 at 13:06

            I'm trying to get sentence vectors from hidden states in a BERT model. Looking at the huggingface BertModel instructions here, which say:

            ...

            ANSWER

            Answered 2020-Aug-18 at 16:31

            I don't think there is single authoritative documentation saying what to use and when. You need to experiment and measure what is best for your task. Recent observations about BERT are nicely summarized in this paper: https://arxiv.org/pdf/2002.12327.pdf.

            I think the rule of thumb is:

            • Use the last layer if you are going to fine-tune the model for your specific task. And finetune whenever you can, several hundred or even dozens of training examples are enough.

            • Use some of the middle layers (7-th or 8-th) if you cannot finetune the model. The intuition behind that is that the layers first develop a more and more abstract and general representation of the input. At some point, the representation starts to be more target to the pre-training task.

            Bert-as-services uses the last layer by default (but it is configurable). Here, it would be [:, -1]. However, it always returns a list of vectors for all input tokens. The vector corresponding to the first special (so-called [CLS]) token is considered to be the sentence embedding. This where the [0] comes from in the snipper you refer to.

            Source https://stackoverflow.com/questions/63461262

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install bert-as-service

            Install the server and client via pip. They can be installed separately or even on different machines:.
            Download a model listed below, then uncompress the zip file into some folder, say /tmp/english_L-12_H-768_A-12/. Optional: fine-tuning the model on your downstream task. Why is it optional?.
            Building a QA semantic search engine in 3 min.
            Serving a fine-tuned BERT model
            Getting ELMo-like contextual word embedding
            Using your own tokenizer
            Using BertClient with tf.data API
            Training a text classifier using BERT features and tf.estimator API
            Saving and loading with TFRecord data
            Asynchronous encoding
            Broadcasting to multiple clients
            Monitoring the service status in a dashboard
            Using bert-as-service to serve HTTP requests in JSON
            Starting BertServer from Python

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/hanxiao/bert-as-service.git

          • CLI

            gh repo clone hanxiao/bert-as-service

          • sshUrl

            git@github.com:hanxiao/bert-as-service.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link