Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐ŸŒ [i18n-KO] Translating guides/hf_file_system.md to Korean #2146

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/ko/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
title: ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œํ•˜๊ธฐ
- local: in_translation
title: (๋ฒˆ์—ญ ์ค‘) Upload files
- local: in_translation
title: (๋ฒˆ์—ญ ์ค‘) HfFileSystem
- local: hf_file_system
heuristicwave marked this conversation as resolved.
Show resolved Hide resolved
title: HfํŒŒ์ผ์‹œ์Šคํ…œ
heuristicwave marked this conversation as resolved.
Show resolved Hide resolved
- local: in_translation
title: (๋ฒˆ์—ญ ์ค‘) Repository
- local: in_translation
Expand Down
109 changes: 109 additions & 0 deletions docs/source/ko/guides/hf_file_system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<!--โš ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->

# Hugging Face Hub์—์„œ ํŒŒ์ผ ์‹œ์Šคํ…œ API๋ฅผ ํ†ตํ•ด ์ƒํ˜ธ์ž‘์šฉํ•˜๊ธฐ[[interact-with-the-hub-through-the-filesystem-api]]

`huggingface_hub` ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” [`HfApi`] ์™ธ์—๋„ Hugging Face Hub์— ๋Œ€ํ•œ ํŒŒ์ด์จ๋‹‰ํ•œ [fsspec-compatible](https://filesystem-spec.readthedocs.io/en/latest/) ํŒŒ์ผ ์ธํ„ฐํŽ˜์ด์Šค์ธ [`HfFileSystem`]์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. [`HfFileSystem`]์€ [`HfApi`] ์œ„์— ๊ตฌ์ถ•๋˜์–ด ์žˆ์œผ๋ฉฐ `cp`, `mv`, `ls`, `du`, `glob`, `get_file` ๋ฐ `put_file`๊ณผ ๊ฐ™์€ ์ „ํ˜•์ ์ธ ํŒŒ์ผ ์‹œ์Šคํ…œ ์Šคํƒ€์ผ ์ž‘์—…์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
heuristicwave marked this conversation as resolved.
Show resolved Hide resolved

## ์‚ฌ์šฉ๋ฒ•[[usage]]

```python
>>> from huggingface_hub import HfFileSystem
>>> fs = HfFileSystem()

>>> # List all files in a directory
>>> fs.ls("datasets/my-username/my-dataset-repo/data", detail=False)
['datasets/my-username/my-dataset-repo/data/train.csv', 'datasets/my-username/my-dataset-repo/data/test.csv']

>>> # List all ".csv" files in a repo
>>> fs.glob("datasets/my-username/my-dataset-repo/**.csv")
['datasets/my-username/my-dataset-repo/data/train.csv', 'datasets/my-username/my-dataset-repo/data/test.csv']

>>> # Read a remote file
>>> with fs.open("datasets/my-username/my-dataset-repo/data/train.csv", "r") as f:
... train_data = f.readlines()

>>> # Read the content of a remote file as a string
>>> train_data = fs.read_text("datasets/my-username/my-dataset-repo/data/train.csv", revision="dev")

>>> # Write a remote file
>>> with fs.open("datasets/my-username/my-dataset-repo/data/validation.csv", "w") as f:
... f.write("text,label")
... f.write("Fantastic movie!,good")
```

์„ ํƒ์  `revision` ์ธ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜์—ฌ ๋ธŒ๋žœ์น˜, ํƒœ๊ทธ ์ด๋ฆ„ ๋˜๋Š” ์ปค๋ฐ‹ ํ•ด์‹œ์™€ ๊ฐ™์€ ํŠน์ • ์ปค๋ฐ‹์—์„œ ์ž‘์—…์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
heuristicwave marked this conversation as resolved.
Show resolved Hide resolved

ํŒŒ์ด์ฌ์— ๋‚ด์žฅ๋œ `open`๊ณผ ๋‹ฌ๋ฆฌ `fsspec`์˜ `open`์€ ๋ฐ”์ด๋„ˆ๋ฆฌ ๋ชจ๋“œ `"rb"`๋กœ ๊ธฐ๋ณธ ์„ค์ •๋ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ํ…์ŠคํŠธ ๋ชจ๋“œ์—์„œ ์ฝ๊ธฐ ์œ„ํ•ด `"r"`, ์“ฐ๊ธฐ ์œ„ํ•ด `"w"`๋กœ ๋ชจ๋“œ๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์„ค์ •ํ•ด์•ผ ํ•จ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ํŒŒ์ผ์— ์ถ”๊ฐ€ํ•˜๊ธฐ(๋ชจ๋“œ `"a"` ๋ฐ `"ab"`)๋Š” ์•„์ง ์ง€์›๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

## ํ†ตํ•ฉ[[integrations]]

[`HfFileSystem`]์€ URL์ด ๋‹ค์Œ ๊ตฌ๋ฌธ์„ ๋”ฐ๋ฅด๋Š” ๊ฒฝ์šฐ `fsspec`์„ ํ†ตํ•ฉํ•˜๋Š” ๋ชจ๋“  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

```
hf://[<repo_type_prefix>]<repo_id>[@<revision>]/<path/in/repo>
```

์—ฌ๊ธฐ์„œ `repo_type_prefix`๋Š” Datasets์˜ ๊ฒฝ์šฐ `datasets/`, Spaces์˜ ๊ฒฝ์šฐ `spaces/`์ด๋ฉฐ, ๋ชจ๋ธ์—๋Š” URL์— ์ ‘๋‘์‚ฌ๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

[`HfFileSystem`]์ด Hub์™€์˜ ์ƒํ˜ธ์ž‘์šฉ์„ ๋‹จ์ˆœํ™”ํ•˜๋Š” ๋ช‡ ๊ฐ€์ง€ ํฅ๋ฏธ๋กœ์šด ํ†ตํ•ฉ ์‚ฌ๋ก€๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

* Hub ์ €์žฅ์†Œ์—์„œ [Pandas](https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#reading-writing-remote-files) DataFrame ์ฝ๊ธฐ/์“ฐ๊ธฐ:

```python
>>> import pandas as pd

>>> # Read a remote CSV file into a dataframe
>>> df = pd.read_csv("hf://datasets/my-username/my-dataset-repo/train.csv")

>>> # Write a dataframe to a remote CSV file
>>> df.to_csv("hf://datasets/my-username/my-dataset-repo/test.csv")
```

๋™์ผํ•œ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ [Dask](https://docs.dask.org/en/stable/how-to/connect-to-remote-data.html) ๋ฐ [Polars](https://pola-rs.github.io/polars/py-polars/html/reference/io.html) DataFrame์—๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

* [DuckDB](https://duckdb.org/docs/guides/python/filesystems)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ (์›๊ฒฉ) ํ—ˆ๋ธŒ ํŒŒ์ผ ์ฟผ๋ฆฌ:
heuristicwave marked this conversation as resolved.
Show resolved Hide resolved

```python
>>> from huggingface_hub import HfFileSystem
>>> import duckdb

>>> fs = HfFileSystem()
>>> duckdb.register_filesystem(fs)
>>> # Query a remote file and get the result back as a dataframe
>>> fs_query_file = "hf://datasets/my-username/my-dataset-repo/data_dir/data.parquet"
>>> df = duckdb.query(f"SELECT * FROM '{fs_query_file}' LIMIT 10").df()
```

* [Zarr](https://zarr.readthedocs.io/en/stable/tutorial.html#io-with-fsspec)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Hub๋ฅผ ๋ฐฐ์—ด ์ €์žฅ์†Œ๋กœ ์‚ฌ์šฉ:

```python
>>> import numpy as np
>>> import zarr

>>> embeddings = np.random.randn(50000, 1000).astype("float32")

>>> # Write an array to a repo
>>> with zarr.open_group("hf://my-username/my-model-repo/array-store", mode="w") as root:
... foo = root.create_group("embeddings")
... foobar = foo.zeros('experiment_0', shape=(50000, 1000), chunks=(10000, 1000), dtype='f4')
... foobar[:] = embeddings

>>> # Read an array from a repo
>>> with zarr.open_group("hf://my-username/my-model-repo/array-store", mode="r") as root:
... first_row = root["embeddings/experiment_0"][0]
```

## ์ธ์ฆ[[authentication]]

๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ Hub์™€ ์ƒํ˜ธ์ž‘์šฉํ•˜๋ ค๋ฉด Hugging Face ๊ณ„์ •์— ๋กœ๊ทธ์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Hub์—์„œ ์ธ์ฆ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด ๋ฌธ์„œ์˜ [์ธ์ฆ](../quick-start#authentication) ์„น์…˜์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๋˜ํ•œ [`HfFileSystem`]์— `token`์„ ์ธ์ˆ˜๋กœ ์ „๋‹ฌํ•˜์—ฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ฐฉ์‹์œผ๋กœ ๋กœ๊ทธ์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

```python
>>> from huggingface_hub import HfFileSystem
>>> fs = HfFileSystem(token=token)
```

์ด๋ ‡๊ฒŒ ๋กœ๊ทธ์ธํ•˜๋Š” ๊ฒฝ์šฐ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ๊ณต์œ ํ•  ๋•Œ ํ† ํฐ์ด ์‹ค์ˆ˜๋กœ ๋ˆ„์ถœ๋˜์ง€ ์•Š๋„๋ก ์ฃผ์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค!
Loading