semvec/pypi-packages huggingface dataset:
temppath 2021.236.907
A quick way to get a temporary pathlib.Path.
License: MIT
Requires Python: >=3.4

# temppath

Provides a quick way to get a `pathlib.Path` file in the system-defined
temporary space.  `temppath` does _not_ wrap `tempfile.NamedTemporaryFile`,
as that automatically deletes on close, and does not allow the same file to be
written, closed, then read [in Windows](https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile),
which is inconsistent with the Unix implementation.  Since `temppath`
provides `pathlib.Path` objects, this is not an issue.

## Usage

There is a nice context manager, which will remove the path for you.

```python
from temppath import TemporaryPathContext

with TemporaryPathContext() as t:
    t.write_text('the quick brown fox jumps over the lazy dog')
    ...
    do_something_awesome_that_reads(t)

# The file is removed when you leave the `with` context.
```

You also have the option to just clean it up yourself if you need more control.

```python
from temppath import TemporaryPath

t = TemporaryPath()
t.write_text('the quick brown fox jumps over the lazy dog')
...
do_something_awesome_that_reads(t)
...
t.unlink()
```
badgey 0.2.3
A library and a CLI to locally generate project badges
License: MIT
Requires Python: >=3.7,<4.0

# Badgey
[![pipeline status](https://gitlab.com/rubendibattista/badgey/badges/master/pipeline.svg)](https://gitlab.com/rubendibattista/badgey/commits/master)
[![loc](https://gitlab.com/rubendibattista/badgey/-/jobs/artifacts/master/raw/loc.svg?job=badges)](https://gitlab.com/rubendibattista/badgey/master)
[![version](https://gitlab.com/rubendibattista/badgey/-/jobs/artifacts/master/raw/version.svg?job=badges)](https://gitlab.com/rubendibattista/badgey/-/releases)
dime-pytorch 1.0.1
PyTorch-implementation of the DIME method to detect out-of-distribution observations in deep learning.
License: MIT
Requires Python: >=3.6

# Distance to Modelled Embedding (DIME)

This repo contains an implementation of DIME, which is a method to detect out-of-distribution (OOD) observations in deep 
learning. DIME provides a flexible method to detect OOD-observations with minimal computational overhead and simply assumes
access to intermediate features from an ANN.

![Schematic describing DIME](dime.png)

The workflow how DIME works is summarized in four steps.

1. Given a trained ANN and training set observations, obtain intermediate feature representations of the
   training set observations (here denoted embedding). If the embeddings are higher than 2-dimensional, 
   aggregate to a 2D-matrix NxP-matrix (for instance by global average pooling in the context of 
   NxCxHxW-representations from a CNN).
3. Linearly approximate the training set embedding by a hyperplane found by truncated singular value decomposition.
4. Given new observations, obtain the corresponding intermediate representation.
5. In the embedding space, measure the distance to the hyperplane (modelled embedding) to determine whether 
   observations are OOD.

In an optional step following 2., you can calibrate the distances against a calibration set to obtain probabilities of 
observing an observation with less than or equal distance to the observed distance.

## Get started
Simply install from pip:
```
pip install dime-pytorch
```

## Examples
Given a 2D-tensor, fit the hyperplane.

    from dime import DIME

    x = torch.tensor(...) # N x P torch 2D float-tensor.
    modelled_embedding = DIME().fit(x)

To obtain probabilities, calibrate percentiles. Preferably against
separate dataset. Chaining is fine.:


    x_cal = torch.tensor(...)  # N_cal x P torch 2D float-tensor.
    modelled_embedding = DIME().fit(x).calibrate(x_cal)

Given fitted hyperplane, you can calculate distances on new observations:

    x_new = torch.tensor(...)  # N_new x P 2D float-tensor.
    modelled_embedding.distance_to_hyperplane(x_new)  # -> 1D float-tensor, length N_new

To obtain probabilities of that the new observations have a distance
calibration set observations are equal or less than the new distance, 
you need to have calibrated the percentiles as shown above. Then you
receive the probablities by passing `return_probablities`-keyword:

    modelled_embedding.distance_to_hyperplane(x_new, return_probabilites=True) # -> 1D float-tensor, length N_new

You can also use the alternative formulation of distance within the hyperplane, optionally as probabilities:

    modelled_embedding.distance_within_hyperplane(x_new)  # -> 1D float-tensor, length N_new

## License

Distributed under the MIT-license. See LICENSE for more information.

Â© 2021 Sartorius AG