Unable to find examples on using DPR for transfer learning,request you to provide examples
Author: MaheshChandrra
Pull request: no

Hi Team Hugging face

Can you please provide a Q and A example for retrieval of an answer for a given text using DPR,I've read the documentation but couldn't find it. Would be of great help.

Thanks
Mahesh Mareedu

@lhoestq 

Comments:
Hi ! There are a few examples in the `datasets` documentation. It shows how to add a FAISS index to a dataset to perform dense retrieval using DPR:
https://huggingface.co/docs/datasets/faiss_and_ea.html#adding-a-faiss-index

Thanks for the link,I tried using elasticsearch from my notebook and getting the below error,any help would be useful,Thanks.

```
from datasets import load_dataset
squad = load_dataset('squad', split='validation')
squad.add_elasticsearch_index("context", host="localhost", port="9200")

---------------------------------------------------------------------------
ConnectionRefusedError                    Traceback (most recent call last)
~\Anaconda3\lib\site-packages\urllib3\connection.py in _new_conn(self)
    158         try:
--> 159             conn = connection.create_connection(
    160                 (self._dns_host, self.port), self.timeout, **extra_kw

~\Anaconda3\lib\site-packages\urllib3\util\connection.py in create_connection(address, timeout, source_address, socket_options)
     83     if err is not None:
---> 84         raise err
     85 

~\Anaconda3\lib\site-packages\urllib3\util\connection.py in create_connection(address, timeout, source_address, socket_options)
     73                 sock.bind(source_address)
---> 74             sock.connect(sa)
     75             return sock

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

During handling of the above exception, another exception occurred:

NewConnectionError                        Traceback (most recent call last)
~\Anaconda3\lib\site-packages\elasticsearch\connection\http_urllib3.py in perform_request(self, method, url, params, body, timeout, ignore, headers)
    244 
--> 245             response = self.pool.urlopen(
    246                 method, url, body, retries=Retry(False), headers=request_headers, **kw

~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    723 
--> 724             retries = retries.increment(
    725                 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]

~\Anaconda3\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    378             # Disabled, indicate to re-raise the error.
--> 379             raise six.reraise(type(error), error, _stacktrace)
    380 

~\Anaconda3\lib\site-packages\urllib3\packages\six.py in reraise(tp, value, tb)
    734                 raise value.with_traceback(tb)
--> 735             raise value
    736         finally:

~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    669             # Make the request on the httplib connection object.
--> 670             httplib_response = self._make_request(
    671                 conn,

~\Anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    391         else:
--> 392             conn.request(method, url, **httplib_request_kw)
    393 

~\Anaconda3\lib\http\client.py in request(self, method, url, body, headers, encode_chunked)
   1239         """Send a complete request to the server."""
-> 1240         self._send_request(method, url, body, headers, encode_chunked)
   1241 

~\Anaconda3\lib\http\client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1285             body = _encode(body, 'body')
-> 1286         self.endheaders(body, encode_chunked=encode_chunked)
   1287 

~\Anaconda3\lib\http\client.py in endheaders(self, message_body, encode_chunked)
   1234             raise CannotSendHeader()
-> 1235         self._send_output(message_body, encode_chunked=encode_chunked)
   1236 

~\Anaconda3\lib\http\client.py in _send_output(self, message_body, encode_chunked)
   1005         del self._buffer[:]
-> 1006         self.send(msg)
   1007 

~\Anaconda3\lib\http\client.py in send(self, data)
    945             if self.auto_open:
--> 946                 self.connect()
    947             else:

~\Anaconda3\lib\site-packages\urllib3\connection.py in connect(self)
    186     def connect(self):
--> 187         conn = self._new_conn()
    188         self._prepare_conn(conn)

~\Anaconda3\lib\site-packages\urllib3\connection.py in _new_conn(self)
    170         except SocketError as e:
--> 171             raise NewConnectionError(
    172                 self, "Failed to establish a new connection: %s" % e

NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000002AF86A1A670>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
<ipython-input-2-91302caec2e8> in <module>
      1 from datasets import load_dataset
      2 squad = load_dataset('squad', split='validation')
----> 3 squad.add_elasticsearch_index("context", host="10.41.128.179", port="8082")

~\Anaconda3\lib\site-packages\datasets\arrow_dataset.py in add_elasticsearch_index(self, column, index_name, host, port, es_client, es_index_name, es_index_config)
   3040         """
   3041         with self.formatted_as(type=None, columns=[column]):
-> 3042             super().add_elasticsearch_index(
   3043                 column=column,
   3044                 index_name=index_name,

~\Anaconda3\lib\site-packages\datasets\search.py in add_elasticsearch_index(self, column, index_name, host, port, es_client, es_index_name, es_index_config)
    539             host=host, port=port, es_client=es_client, es_index_name=es_index_name, es_index_config=es_index_config
    540         )
--> 541         es_index.add_documents(self, column=column)
    542         self._indexes[index_name] = es_index
    543 

~\Anaconda3\lib\site-packages\datasets\search.py in add_documents(self, documents, column)
    140         index_name = self.es_index_name
    141         index_config = self.es_index_config
--> 142         self.es_client.indices.create(index=index_name, body=index_config)
    143         number_of_docs = len(documents)
    144         not_verbose = bool(logger.getEffectiveLevel() > WARNING)

~\Anaconda3\lib\site-packages\elasticsearch\client\utils.py in _wrapped(*args, **kwargs)
    150                 if p in kwargs:
    151                     params[p] = kwargs.pop(p)
--> 152             return func(*args, params=params, headers=headers, **kwargs)
    153 
    154         return _wrapped

~\Anaconda3\lib\site-packages\elasticsearch\client\indices.py in create(self, index, body, params, headers)
    121             raise ValueError("Empty value passed for a required argument 'index'.")
    122 
--> 123         return self.transport.perform_request(
    124             "PUT", _make_path(index), params=params, headers=headers, body=body
    125         )

~\Anaconda3\lib\site-packages\elasticsearch\transport.py in perform_request(self, method, url, headers, params, body)
    388                     # raise exception on last retry
    389                     if attempt == self.max_retries:
--> 390                         raise e
    391                 else:
    392                     raise e

~\Anaconda3\lib\site-packages\elasticsearch\transport.py in perform_request(self, method, url, headers, params, body)
    356 
    357             try:
--> 358                 status, headers_response, data = connection.perform_request(
    359                     method,
    360                     url,

~\Anaconda3\lib\site-packages\elasticsearch\connection\http_urllib3.py in perform_request(self, method, url, params, body, timeout, ignore, headers)
    256             if isinstance(e, ReadTimeoutError):
    257                 raise ConnectionTimeout("TIMEOUT", str(e), e)
--> 258             raise ConnectionError("N/A", str(e), e)
    259 
    260         # raise warnings if any from the 'Warnings' header.

ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x000002AF86A1A670>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x000002AF86A1A670>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it)
```


Hi ! Did you start elasticsearch on your machine ? Could you also check that you used the right port ?

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.