- Notifications
You must be signed in to change notification settings - Fork 5.4k
KO: add site/ko/swift/python_interoperability.ipynb #1062
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
Changes from 1 commit
af04a90 39fade6 33dc8fb 527ee2f 5e365e3 561903a 60ae220 a913e36 be24958 8b0af42 4a33694 8873b44 1e33f91 01503fc d9bdb60 1179962 4c359a2 4f44aaa 9ea40b5 aee2b72 35a493b 4402409 00d8e75 6b41054 3175a99 323dfcf 3af777d 9093099 d8bb21a 2378372 e9f2d66 535019d bb71ff6 0ccf422 0a2d3f1 b1bdc2e 6dd1bc6 06c2eea 7f7c4d1 df44872 77e7f4b 0b3a34e f6f7366 7191bb0 f7b3c58 5ffd04c 5c582a9 e5c25cc 24b9a38 012aa5d 03dba97 01ba431 f78414c File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -61,11 +61,10 @@ | |
| "id": "8sa42_NblqRE" | ||
| }, | ||
| "source": [ | ||
| "# Python interoperability\n", | ||
| "# 파이썬 상호 호환성\n", | ||
| "\n", | ||
| "Swift For TensorFlow supports Python interoperability.\n", | ||
| "\n", | ||
| "You can import Python modules from Swift, call Python functions, and convert values between Swift and Python." | ||
| "텐서플로우를 위한 스위프트는 파이썬 상호 호환성을 지원합니다.\n", | ||
| "스위프트에서 파이썬 모듈을 임포트해서, 스위프트와 파이썬 사이의 값을 바꾸거나 파이썬 함수를 호출할 수 있습니다." | ||
| ] | ||
| }, | ||
| { | ||
| | @@ -99,29 +98,29 @@ | |
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Setting the Python version" | ||
| "## 파이썬 버전 설정" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "By default, when you `import Python`, Swift searches system library paths for the newest version of Python installed. \n", | ||
| "To use a specific Python installation, set the `PYTHON_LIBRARY` environment variable to the `libpython` shared library provided by the installation. For example: \n", | ||
| "기본적으로 파이썬을 임포트 하면, 스위프트는 시스템 라이브러리 경로를 검색하여 설치된 최신 버전의 파이썬을 검색합니다.\n", | ||
| "특정한 파이썬을 설치하고자 할 때, 설치에서 제공하는 `libpython` 공유 라이브러리로 `PYTHON_LIBRARY` 환경변수를 설정해야 합니다.\n", | ||
| "\n", | ||
| "`export PYTHON_LIBRARY=\"~/anaconda3/lib/libpython3.7m.so\"`\n", | ||
| "예시: `\"export PYTHON_LIBRARY=\"~/anaconda3/\n", | ||
| "lib/libpython3.7m.so\"`\n", | ||
| "\n", | ||
| "The exact filename will differ across Python environments and platforms." | ||
| "정확한 파일명은 파이썬 환경과 플랫폼마다 다를 수 있습니다." | ||
| ] | ||
| }, | ||
| | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Alternatively, you can set the `PYTHON_VERSION` environment variable, which instructs Swift to search system library paths for a matching Python version. Note that `PYTHON_LIBRARY` takes precedence over `PYTHON_VERSION`.\n", | ||
| "또는 스위프트에 일치하는 파이썬 버전에 대한 시스템 라이브러리 경로를 검색하도록 알려주는 `PYTHON_VERSION` 환경변수를 설정할 수 있습니다. `PYTHON_LIBRARY`가 `PYTHON_VERSION`보다 우선한다는 점을 유의해야 합니다.\n", | ||
| "\n", | ||
| "In code, you can also call the `PythonLibrary.useVersion` function, which is equivalent to setting `PYTHON_VERSION`." | ||
| "또한 코드에서 `PYTHON_VERSION` 설정과 동일한 `PythonLibrary.useVersion`함수를 호출할 수 있습니다." | ||
| ] | ||
| }, | ||
| { | ||
| | @@ -138,14 +137,15 @@ | |
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "__Note: you should run `PythonLibrary.useVersion` right after `import Python`, before calling any Python code. It cannot be used to dynamically switch Python versions.__" | ||
| "_노트: \n", | ||
| "파이썬을 임포트한 직후, 파이썬 코드를 호출하기 전에`PythonLibrary.useVersion`을 실행해야 합니다._\n" | ||
| ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Set `PYTHON_LOADER_LOGGING=1` to see [debug output for Python library loading](https://github.com/apple/swift/pull/20674#discussion_r235207008). " | ||
| "`PYTHON_LOADER_LOGGING=1` 설정은 [debug output for Python library loading](https://github.com/apple/swift/pull/20674#discussion_r235207008)을 참고하세요." | ||
| ||
| ] | ||
| }, | ||
| { | ||
| | @@ -155,14 +155,13 @@ | |
| "id": "rU0WY_sJodio" | ||
| }, | ||
| "source": [ | ||
| "## Basics\n", | ||
| "\n", | ||
| "In Swift, `PythonObject` represents an object from Python.\n", | ||
| "All Python APIs use and return `PythonObject` instances.\n", | ||
| "## 기본\n", | ||
| "스위프트에서, `PythonObject`는 파이썬에서 객체를 나타냅니다.\n", | ||
| ||
| "모든 파이썬 API는 `PythonObject` 인스턴스를 사용하거나 반환합니다.\n", | ||
| "\n", | ||
| "Basic types in Swift (like numbers and arrays) are convertible to `PythonObject`. In some cases (for literals and functions taking `PythonConvertible` arguments), conversion happens implicitly. To explicitly cast a Swift value to `PythonObject`, use the `PythonObject` initializer.\n", | ||
| "스위프트(숫자 및 배열처럼)에서 기본형은 `PythonObject`로 전환할 수 있습니다. 몇몇 경우에 (\"PythonConvertible\" 인수를 받는 리터럴과 함수의 경우), 변환이 암묵적으로 일어납니다. 스위프트 값을 `PythonObject`에 명시적으로 지정하려면 `PythonObject` 이니셜라이저를 사용합니다.\n", | ||
| "\n", | ||
| "`PythonObject` defines many standard operations, including numeric operations, indexing, and iteration." | ||
| "`PythonObject`는 숫자 연산, 인덱싱, 반복을 포함한 많은 표준 연산을 정의합니다." | ||
| ] | ||
| }, | ||
| { | ||
| | @@ -191,15 +190,15 @@ | |
| } | ||
| ], | ||
| "source": [ | ||
| "// Convert standard Swift types to Python.\n", | ||
| "// 표준 스위프트 유형을 Python으로 변환합니다.\n", | ||
| "let pythonInt: PythonObject = 1\n", | ||
| "let pythonFloat: PythonObject = 3.0\n", | ||
| "let pythonString: PythonObject = \"Hello Python!\"\n", | ||
| "let pythonRange: PythonObject = PythonObject(5..<10)\n", | ||
| "let pythonArray: PythonObject = [1, 2, 3, 4]\n", | ||
| "let pythonDict: PythonObject = [\"foo\": [0], \"bar\": [1, 2, 3]]\n", | ||
| "\n", | ||
| "// Perform standard operations on Python objects.\n", | ||
| "// 파이썬 객체에 표준 연산을 수행합니다.\n", | ||
| "print(pythonInt + pythonFloat)\n", | ||
| "print(pythonString[0..<6])\n", | ||
| "print(pythonRange)\n", | ||
| | @@ -233,16 +232,16 @@ | |
| } | ||
| ], | ||
| "source": [ | ||
| "// Convert Python objects back to Swift.\n", | ||
| "// 파이썬 객체를 다시 스위프트로 변환합니다.\n", | ||
| "let int = Int(pythonInt)!\n", | ||
| "let float = Float(pythonFloat)!\n", | ||
| "let string = String(pythonString)!\n", | ||
| "let range = Range<Int>(pythonRange)!\n", | ||
| "let array: [Int] = Array(pythonArray)!\n", | ||
| "let dict: [String: [Int]] = Dictionary(pythonDict)!\n", | ||
| "\n", | ||
| "// Perform standard operations.\n", | ||
| "// Outputs are the same as Python!\n", | ||
| "// 표준 연산을 수행합니다.\n", | ||
| "// 출력은 파이썬과 동일합니다!\n", | ||
| "print(Float(int) + float)\n", | ||
| "print(string.prefix(6))\n", | ||
| "print(range)\n", | ||
| | @@ -257,16 +256,16 @@ | |
| "id": "1pMewsl0VgnJ" | ||
| }, | ||
| "source": [ | ||
| "`PythonObject` defines conformances to many standard Swift protocols:\n", | ||
| "* `Equatable`\n", | ||
| "* `Comparable`\n", | ||
| "* `Hashable`\n", | ||
| "* `SignedNumeric`\n", | ||
| "* `Strideable`\n", | ||
| "* `MutableCollection`\n", | ||
| "* All of the `ExpressibleBy_Literal` protocols\n", | ||
| "`PythonObject`는 많은 표준 스위프트 프로토콜에 대한 적합성을 정의합니다.\n", | ||
| "* `동시성`\n", | ||
| "* `비교성`\n", | ||
| "* `해쉬적`\n", | ||
| "* `정수`\n", | ||
| "* `변할 수 있는 수집`\n", | ||
| "* `리터럴에 의해 표현가능한` 모든 프로토콜\n", | ||
| "\n", | ||
| "Note that these conformances are not type-safe: crashes will occur if you attempt to use protocol functionality from an incompatible `PythonObject` instance." | ||
| "노트: 이러한 형식은 안전하지 않습니다.\n", | ||
| ||
| "충돌은 호환되지 않는 `PythonObject` 인스턴스에서 프로토콜 기능을 사용하려고 할 때 발생합니다." | ||
| ] | ||
| }, | ||
| { | ||
| | @@ -314,9 +313,9 @@ | |
| "id": "w3lmTRCWT5sS" | ||
| }, | ||
| "source": [ | ||
| "To convert tuples from Python to Swift, you must statically know the arity of the tuple.\n", | ||
| "튜플을 파이썬에서 스위프트로 변환하려면, 정적으로 투플의 열성을 알아야 합니다.\n", | ||
| ||
| "\n", | ||
| "Call one of the following instance methods:\n", | ||
| "다음 인스턴스 방법 중 하나를 호출합니다:\n", | ||
| ||
| "- `PythonObject.tuple2`\n", | ||
| "- `PythonObject.tuple3`\n", | ||
| "- `PythonObject.tuple4`" | ||
| | @@ -360,9 +359,9 @@ | |
| "id": "Te7sNNx9c_am" | ||
| }, | ||
| "source": [ | ||
| "## Python builtins\n", | ||
| "## 파이썬 내장객체\n", | ||
| "\n", | ||
| "Access Python builtins via the global `Python` interface." | ||
| "Python의 전역 인터페이스를 활용해 Python 내장 객체에 진입합니다." | ||
| ||
| ] | ||
| }, | ||
| { | ||
| | @@ -389,10 +388,10 @@ | |
| } | ||
| ], | ||
| "source": [ | ||
| "// `Python.builtins` is a dictionary of all Python builtins.\n", | ||
| "// `Python.builtins`은 모든 파이썬 내장객체의 딕셔너리입니다.\n", | ||
| ||
| "_ = Python.builtins\n", | ||
| "\n", | ||
| "// Try some Python builtins.\n", | ||
| "// 파이썬 내장 객체를 시도합니다.\n", | ||
| ||
| "print(Python.type(1))\n", | ||
| "print(Python.len([1, 2, 3]))\n", | ||
| "print(Python.sum([1, 2, 3]))" | ||
| | @@ -405,9 +404,9 @@ | |
| "id": "H2wwUL1tY3JX" | ||
| }, | ||
| "source": [ | ||
| "## Importing Python modules\n", | ||
| "## 파이썬 모듈 임포트\n", | ||
| "\n", | ||
| "Use `Python.import` to import a Python module. It works like the `import` keyword in `Python`." | ||
| "`Python.import`를 사용하여 `Python` 모듈을 임포트합니다. 이것은 파이썬의 `import` 키워드처럼 동작합니다." | ||
| ] | ||
| }, | ||
| { | ||
| | @@ -447,7 +446,7 @@ | |
| "id": "hQvza3dUXlr0" | ||
| }, | ||
| "source": [ | ||
| "Use the throwing function `Python.attemptImport` to perform safe importing." | ||
| "안전하게 패키지를 가져오기 위해 예외처리 함수 `Python.attemptImport`를 사용합니다." | ||
| ] | ||
| }, | ||
| { | ||
| | @@ -483,16 +482,21 @@ | |
| "id": "Qej_Z6V3mZnG" | ||
| }, | ||
| "source": [ | ||
| "## Conversion with `numpy.ndarray`\n", | ||
| "## `numpy.ndarray`로 변환\n", | ||
| "\n", | ||
| "The following Swift types can be converted to and from `numpy.ndarray`:\n", | ||
| "- `Array<Element>`\n", | ||
| "- `ShapedArray<Scalar>`\n", | ||
| "- `Tensor<Scalar>`\n", | ||
| "\n", | ||
| ||
| "Conversion succeeds only if the `dtype` of the `numpy.ndarray` is compatible with the `Element` or `Scalar` generic parameter type.\n", | ||
| "다음 스위프트 유형은 `numpy.ndarray`로 변환할 수 있습니다.\n", | ||
| "- `Array<Element>`\n", | ||
| "- `ShapedArray<Scalar>`\n", | ||
| "- `Tensor<Scalar>`\n", | ||
| "\n", | ||
| "`Numpy.ndarray`의 `dtype`이 `Element` 또는 `Scalar`의 일반 파라미터 타입과 호환되어야만 변환이 성공합니다.\n", | ||
| "\n", | ||
| "For `Array`, conversion from `numpy` succeeds only if the `numpy.ndarray` is 1-D." | ||
| "`Array`의 경우 `numpy.ndarray`가 1-D일 경우에만 `numpy`에서 변환이 성공합니다." | ||
| ] | ||
| }, | ||
| { | ||
| | @@ -551,17 +555,17 @@ | |
| } | ||
| ], | ||
| "source": [ | ||
| "// Examples of converting `numpy.ndarray` to Swift types.\n", | ||
| "// `numpy.ndarray`에서 스위프트 타입으로 변환하는 예제.\n", | ||
| "let array: [Float] = Array(numpy: numpyArray)!\n", | ||
| "let shapedArray = ShapedArray<Float>(numpy: numpyArray)!\n", | ||
| "let tensor = Tensor<Float>(numpy: numpyArray)!\n", | ||
| "\n", | ||
| "// Examples of converting Swift types to `numpy.ndarray`.\n", | ||
| "// 스위프트 타입에서 `numpy.ndarray`으로 변환하는 예제.\n", | ||
| "print(array.makeNumpyArray())\n", | ||
| "print(shapedArray.makeNumpyArray())\n", | ||
| "print(tensor.makeNumpyArray())\n", | ||
| "\n", | ||
| "// Examples with different dtypes.\n", | ||
| "// dtype이 다른 예제.\n", | ||
| "let doubleArray: [Double] = Array(numpy: np.ones([3], dtype: np.float))!\n", | ||
| "let intTensor = Tensor<Int32>(numpy: np.ones([2, 3], dtype: np.int32))!" | ||
| ] | ||
| | @@ -573,9 +577,9 @@ | |
| "id": "8EQFZZ5iafwh" | ||
| }, | ||
| "source": [ | ||
| "## Displaying images\n", | ||
| "## 이미지 표시\n", | ||
| "\n", | ||
| "You can display images in-line using `matplotlib`, just like in Python notebooks." | ||
| "파이썬 노트북에서처럼 `matplotlib`를 이용해 이미지를 일렬로 표시할 수 있습니다." | ||
| ||
| ] | ||
| }, | ||
| { | ||
| | @@ -617,7 +621,7 @@ | |
| } | ||
| ], | ||
| "source": [ | ||
| "// Setup.\n", | ||
| "// 세트 업.\n", | ||
| ||
| "%include \"EnableIPythonDisplay.swift\"\n", | ||
| "IPythonDisplay.shell.enable_matplotlib(\"inline\")\n", | ||
| "\n", | ||
| | @@ -651,15 +655,21 @@ | |
| "version": "0.3.2" | ||
| }, | ||
| "kernelspec": { | ||
| Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Swift notebooks are a bit different than Python notebooks. You need to manually set the kernel to use Swift in Colab (there's not a UI option, yet). See the original notebook (at the bottom): https://raw.githubusercontent.com/tensorflow/swift/master/docs/site/tutorials/python_interoperability.ipynb I would recommend starting a translation by copying that notebook instead of starting a new one. These should execute in Colab. Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meta data has been modified for Swift. Perhaps the kernel changed while checking on local notebook after work in colab Thank you | ||
| "display_name": "Swift", | ||
| "language": "swift", | ||
| "name": "swift" | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "file_extension": ".swift", | ||
| "mimetype": "text/x-swift", | ||
| "name": "swift", | ||
| "version": "" | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.7.4" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'tensorflow' is translated as '텐서플로' in TF docs.
Please replace '텐서플로우' with '텐서플로'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for review
I changed it from '텐서플로우' to '텐서플로'.