From c5f1b715e8c6df9fa468060c816d283470abe8b7 Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Fri, 27 Sep 2019 16:38:35 +0900 Subject: [PATCH 01/13] KO: copy english doc --- site/ko/guide/tensor.md | 330 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 site/ko/guide/tensor.md diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md new file mode 100644 index 00000000000..299fe7802ca --- /dev/null +++ b/site/ko/guide/tensor.md @@ -0,0 +1,330 @@ +# TensorFlow tensors + +TensorFlow, as the name indicates, is a framework to define and run computations +involving tensors. A *tensor* is a generalization of vectors and matrices to +potentially higher dimensions. Internally, TensorFlow represents tensors as +n-dimensional arrays of base datatypes. + +When writing a TensorFlow program, the main object you manipulate and pass +around is the `tf.Tensor`. A `tf.Tensor` object represents a partially defined +computation that will eventually produce a value. TensorFlow programs work by +first building a graph of `tf.Tensor` objects, detailing how each tensor is +computed based on the other available tensors and then by running parts of this +graph to achieve the desired results. + +A `tf.Tensor` has the following properties: + + * a data type (`float32`, `int32`, or `string`, for example) + * a shape + + +Each element in the Tensor has the same data type, and the data type is always +known. The shape (that is, the number of dimensions it has and the size of each +dimension) might be only partially known. Most operations produce tensors of +fully-known shapes if the shapes of their inputs are also fully known, but in +some cases it's only possible to find the shape of a tensor at graph execution +time. + +Some types of tensors are special, and these will be covered in other +units of the TensorFlow guide. The main ones are: + + * `tf.Variable` + * `tf.constant` + * `tf.placeholder` + * `tf.SparseTensor` + +With the exception of `tf.Variable`, the value of a tensor is immutable, which +means that in the context of a single execution tensors only have a single +value. However, evaluating the same tensor twice can return different values; +for example that tensor can be the result of reading data from disk, or +generating a random number. + +## Rank + +The **rank** of a `tf.Tensor` object is its number of dimensions. Synonyms for +rank include **order** or **degree** or **n-dimension**. +Note that rank in TensorFlow is not the same as matrix rank in mathematics. +As the following table shows, each rank in TensorFlow corresponds to a +different mathematical entity: + +Rank | Math entity +--- | --- +0 | Scalar (magnitude only) +1 | Vector (magnitude and direction) +2 | Matrix (table of numbers) +3 | 3-Tensor (cube of numbers) +n | n-Tensor (you get the idea) + + +### Rank 0 + +The following snippet demonstrates creating a few rank 0 variables: + +```python +mammal = tf.Variable("Elephant", tf.string) +ignition = tf.Variable(451, tf.int16) +floating = tf.Variable(3.14159265359, tf.float64) +its_complicated = tf.Variable(12.3 - 4.85j, tf.complex64) +``` + +Note: A string is treated as a single object in TensorFlow, not as a sequence of +characters. It is possible to have scalar strings, vectors of strings, etc. + +### Rank 1 + +To create a rank 1 `tf.Tensor` object, you can pass a list of items as the +initial value. For example: + +```python +mystr = tf.Variable(["Hello"], tf.string) +cool_numbers = tf.Variable([3.14159, 2.71828], tf.float32) +first_primes = tf.Variable([2, 3, 5, 7, 11], tf.int32) +its_very_complicated = tf.Variable([12.3 - 4.85j, 7.5 - 6.23j], tf.complex64) +``` + + +### Higher ranks + +A rank 2 `tf.Tensor` object consists of at least one row and at least +one column: + +```python +mymat = tf.Variable([[7],[11]], tf.int16) +myxor = tf.Variable([[False, True],[True, False]], tf.bool) +linear_squares = tf.Variable([[4], [9], [16], [25]], tf.int32) +squarish_squares = tf.Variable([ [4, 9], [16, 25] ], tf.int32) +rank_of_squares = tf.rank(squarish_squares) +mymatC = tf.Variable([[7],[11]], tf.int32) +``` + +Higher-rank Tensors, similarly, consist of an n-dimensional array. For example, +during image processing, many tensors of rank 4 are used, with dimensions +corresponding to example-in-batch, image height, image width, and color channel. + +``` python +my_image = tf.zeros([10, 299, 299, 3]) # batch x height x width x color +``` + +### Getting a `tf.Tensor` object's rank + +To determine the rank of a `tf.Tensor` object, call the `tf.rank` method. +For example, the following method programmatically determines the rank +of the `tf.Tensor` defined in the previous section: + +```python +r = tf.rank(my_image) +# After the graph runs, r will hold the value 4. +``` + +### Referring to `tf.Tensor` slices + +Since a `tf.Tensor` is an n-dimensional array of cells, to access a single cell +in a `tf.Tensor` you need to specify n indices. + +For a rank 0 tensor (a scalar), no indices are necessary, since it is already a +single number. + +For a rank 1 tensor (a vector), passing a single index allows you to access a +number: + +```python +my_scalar = my_vector[2] +``` + +Note that the index passed inside the `[]` can itself be a scalar `tf.Tensor`, if +you want to dynamically choose an element from the vector. + +For tensors of rank 2 or higher, the situation is more interesting. For a +`tf.Tensor` of rank 2, passing two numbers returns a scalar, as expected: + + +```python +my_scalar = my_matrix[1, 2] +``` + + +Passing a single number, however, returns a subvector of a matrix, as follows: + + +```python +my_row_vector = my_matrix[2] +my_column_vector = my_matrix[:, 3] +``` + +The `:` notation is python slicing syntax for "leave this dimension alone". This +is useful in higher-rank Tensors, as it allows you to access its subvectors, +submatrices, and even other subtensors. + + +## Shape + +The **shape** of a tensor is the number of elements in each dimension. +TensorFlow automatically infers shapes during graph construction. These inferred +shapes might have known or unknown rank. If the rank is known, the sizes of each +dimension might be known or unknown. + +The TensorFlow documentation uses three notational conventions to describe +tensor dimensionality: rank, shape, and dimension number. The following table +shows how these relate to one another: + +Rank | Shape | Dimension number | Example +--- | --- | --- | --- +0 | [] | 0-D | A 0-D tensor. A scalar. +1 | [D0] | 1-D | A 1-D tensor with shape [5]. +2 | [D0, D1] | 2-D | A 2-D tensor with shape [3, 4]. +3 | [D0, D1, D2] | 3-D | A 3-D tensor with shape [1, 4, 3]. +n | [D0, D1, ... Dn-1] | n-D | A tensor with shape [D0, D1, ... Dn-1]. + +Shapes can be represented via Python lists / tuples of ints, or with the +`tf.TensorShape`. + +### Getting a `tf.Tensor` object's shape + +There are two ways of accessing the shape of a `tf.Tensor`. While building the +graph, it is often useful to ask what is already known about a tensor's +shape. This can be done by reading the `shape` property of a `tf.Tensor` object. +This method returns a `TensorShape` object, which is a convenient way of +representing partially-specified shapes (since, when building the graph, not all +shapes will be fully known). + +It is also possible to get a `tf.Tensor` that will represent the fully-defined +shape of another `tf.Tensor` at runtime. This is done by calling the `tf.shape` +operation. This way, you can build a graph that manipulates the shapes of +tensors by building other tensors that depend on the dynamic shape of the input +`tf.Tensor`. + +For example, here is how to make a vector of zeros with the same size as the +number of columns in a given matrix: + +``` python +zeros = tf.zeros(my_matrix.shape[1]) +``` + +### Changing the shape of a `tf.Tensor` + +The **number of elements** of a tensor is the product of the sizes of all its +shapes. The number of elements of a scalar is always `1`. Since there are often +many different shapes that have the same number of elements, it's often +convenient to be able to change the shape of a `tf.Tensor`, keeping its elements +fixed. This can be done with `tf.reshape`. + +The following examples demonstrate how to reshape tensors: + +```python +rank_three_tensor = tf.ones([3, 4, 5]) +matrix = tf.reshape(rank_three_tensor, [6, 10]) # Reshape existing content into + # a 6x10 matrix +matrixB = tf.reshape(matrix, [3, -1]) # Reshape existing content into a 3x20 + # matrix. -1 tells reshape to calculate + # the size of this dimension. +matrixAlt = tf.reshape(matrixB, [4, 3, -1]) # Reshape existing content into a + #4x3x5 tensor + +# Note that the number of elements of the reshaped Tensors has to match the +# original number of elements. Therefore, the following example generates an +# error because no possible value for the last dimension will match the number +# of elements. +yet_another = tf.reshape(matrixAlt, [13, 2, -1]) # ERROR! +``` + +## Data types + +In addition to dimensionality, Tensors have a data type. Refer to the +`tf.DType` page for a complete list of the data types. + +It is not possible to have a `tf.Tensor` with more than one data type. It is +possible, however, to serialize arbitrary data structures as `string`s and store +those in `tf.Tensor`s. + +It is possible to cast `tf.Tensor`s from one datatype to another using +`tf.cast`: + +``` python +# Cast a constant integer tensor into floating point. +float_tensor = tf.cast(tf.constant([1, 2, 3]), dtype=tf.float32) +``` + +To inspect a `tf.Tensor`'s data type use the `Tensor.dtype` property. + +When creating a `tf.Tensor` from a python object you may optionally specify the +datatype. If you don't, TensorFlow chooses a datatype that can represent your +data. TensorFlow converts Python integers to `tf.int32` and python floating +point numbers to `tf.float32`. Otherwise TensorFlow uses the same rules numpy +uses when converting to arrays. + +## Evaluate tensors + +Once the computation graph has been built, you can run the computation that +produces a particular `tf.Tensor` and fetch the value assigned to it. This is +often useful for debugging as well as being required for much of TensorFlow to +work. + +The simplest way to evaluate a Tensor is using the `Tensor.eval` method. For +example: + +```python +constant = tf.constant([1, 2, 3]) +tensor = constant * constant +print(tensor.eval()) +``` + +The `eval` method only works when a default `tf.Session` is active (see +[Graphs and Sessions](./graphs.md) for more information). + +`Tensor.eval` returns a numpy array with the same contents as the tensor. + +Sometimes it is not possible to evaluate a `tf.Tensor` with no context because +its value might depend on dynamic information that is not available. For +example, tensors that depend on `placeholder`s can't be evaluated without +providing a value for the `placeholder`. + +``` python +p = tf.placeholder(tf.float32) +t = p + 1.0 +t.eval() # This will fail, since the placeholder did not get a value. +t.eval(feed_dict={p:2.0}) # This will succeed because we're feeding a value + # to the placeholder. +``` + +Note that it is possible to feed any `tf.Tensor`, not just placeholders. + +Other model constructs might make evaluating a `tf.Tensor` +complicated. TensorFlow can't directly evaluate `tf.Tensor`s defined inside +functions or inside control flow constructs. If a `tf.Tensor` depends on a value +from a queue, evaluating the `tf.Tensor` will only work once something has been +enqueued; otherwise, evaluating it will hang. When working with queues, remember +to call `tf.train.start_queue_runners` before evaluating any `tf.Tensor`s. + +## Print a tensor + +For debugging purposes you might want to print the value of a `tf.Tensor`. While + [tfdbg](../guide/debugger.md) provides advanced debugging support, TensorFlow also has an + operation to directly print the value of a `tf.Tensor`. + +Note that you rarely want to use the following pattern when printing a +`tf.Tensor`: + +``` python +t = <> +print(t) # This will print the symbolic tensor when the graph is being built. + # This tensor does not have a value in this context. +``` + +This code prints the `tf.Tensor` object (which represents deferred computation) +and not its value. Instead, TensorFlow provides the `tf.Print` operation, which +returns its first tensor argument unchanged while printing the set of +`tf.Tensor`s it is passed as the second argument. + +To correctly use `tf.Print` its return value must be used. See the example below + +``` python +t = <> +tf.Print(t, [t]) # This does nothing +t = tf.Print(t, [t]) # Here we are using the value returned by tf.Print +result = t + 1 # Now when result is evaluated the value of `t` will be printed. +``` + +When you evaluate `result` you will evaluate everything `result` depends +upon. Since `result` depends upon `t`, and evaluating `t` has the side effect of +printing its input (the old value of `t`), `t` gets printed. + From 46bf2fe6891844d38a848eeda121d7c804589973 Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Fri, 27 Sep 2019 17:21:11 +0900 Subject: [PATCH 02/13] KO: translate section intro --- site/ko/guide/tensor.md | 51 +++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index 299fe7802ca..a23364ff46c 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -1,43 +1,38 @@ -# TensorFlow tensors +# 텐서플로 텐서 -TensorFlow, as the name indicates, is a framework to define and run computations -involving tensors. A *tensor* is a generalization of vectors and matrices to -potentially higher dimensions. Internally, TensorFlow represents tensors as -n-dimensional arrays of base datatypes. +이름에서 알 수 있듯이, 텐서플로는 텐서를 포함한 계산을 정의하고 실행하는 프레임워크입니다. +*텐서*는 벡터와 행렬을 일반화한 것이고 고차원으로 확장가능합니다. +내부적으로 텐서플로는 텐서를 n-차원의 기본 데이터형식의 배열로 표현합니다. -When writing a TensorFlow program, the main object you manipulate and pass -around is the `tf.Tensor`. A `tf.Tensor` object represents a partially defined -computation that will eventually produce a value. TensorFlow programs work by -first building a graph of `tf.Tensor` objects, detailing how each tensor is -computed based on the other available tensors and then by running parts of this -graph to achieve the desired results. +텐서플로 프로그램을 작성할 때, 조작하고 전달하는 중요 객체는 `tf.Tensor`입니다. +`tf.Tensor` 객체는 부분적으로 결과적으로는 값으로 변환될 수 있는 계산으로 표현됩니다. +텐서플로 프로그램은 `tf.Tensor` 객체 그래프를 먼저 만드는 것으로 시작하고, +각가의 텐서가 다른 텐서를 기반으로 어떤식으로 계산될 수 있는지 구체화하고, +그 다음 그래프를 실행하서 원하는 결과를 얻게 됩니다. -A `tf.Tensor` has the following properties: +`tf.Tensor`는 다음과 같은 속성을 가지고 있습니다: - * a data type (`float32`, `int32`, or `string`, for example) - * a shape + * 데이터 타입 (예를 들어, `float32` 또는 `int32`, `string`) + * 모양(shape) +텐서안의 각각 요소(element)는 동일한 데이터 타입이고 항상 그 데이터 타입을 알 수 있습니다. +모양(즉, 차원 크기와 각 차원마다 길이(size))는 일부만 알 수 있습니다. +대부분 연산은 입력값 모양을 알 수 있다면 모든 정보를 알 수 있는 텐서를 만들지만, +일부 경우에서는 그래프를 실행한 이후에 텐서 모양을 알 수 있기도 합니다. -Each element in the Tensor has the same data type, and the data type is always -known. The shape (that is, the number of dimensions it has and the size of each -dimension) might be only partially known. Most operations produce tensors of -fully-known shapes if the shapes of their inputs are also fully known, but in -some cases it's only possible to find the shape of a tensor at graph execution -time. - -Some types of tensors are special, and these will be covered in other -units of the TensorFlow guide. The main ones are: +일부 특별한 텐서는 텐서플로 가이드문서의 다른 부분에서 다뤄질 것입니다. +핵심인 텐서는 다음과 같습니다: * `tf.Variable` * `tf.constant` * `tf.placeholder` * `tf.SparseTensor` -With the exception of `tf.Variable`, the value of a tensor is immutable, which -means that in the context of a single execution tensors only have a single -value. However, evaluating the same tensor twice can return different values; -for example that tensor can be the result of reading data from disk, or -generating a random number. +예외인 `tf.Variable`을 제외한다면, 텐서 값은 변경불가능(immutable) 합니다. +즉, 텐서를 한번만 실행시킨 경우에는 오직 하나의 값만을 가집니다. +그러나, 동일한 텐서를 다시 실행시킨다면 다른 값을 가질 수 있습니다: +예를 들어 텐서가 디스크로부터 데이터를 읽어들인 결과 이거나, +무작위 숫자를 생성하는 경우입니다. ## Rank From dcde39758a5e0d7eed1308b8d497c1fc885a98af Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Tue, 1 Oct 2019 16:59:53 +0900 Subject: [PATCH 03/13] KO: translate section 'Rank' --- site/ko/guide/tensor.md | 85 +++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index a23364ff46c..1b6ee46664f 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -34,26 +34,25 @@ 예를 들어 텐서가 디스크로부터 데이터를 읽어들인 결과 이거나, 무작위 숫자를 생성하는 경우입니다. -## Rank +## 랭크(Rank) -The **rank** of a `tf.Tensor` object is its number of dimensions. Synonyms for -rank include **order** or **degree** or **n-dimension**. -Note that rank in TensorFlow is not the same as matrix rank in mathematics. -As the following table shows, each rank in TensorFlow corresponds to a -different mathematical entity: +`tf.Tensor` 객체의 **랭크**는 그 차원의 수입니다. +랭크의 동의어는 **order** 또는 **degree**, **n-차원**입니다. +텐서플로의 랭크는 수학에서 사용하는 행렬의 랭크와는 다릅니다. +다음 표에서 알 수 있는 것처럼, 텐서플로의 각 랭크는 각각 다른 수학적 용어(entity)에 해당됩니다. -Rank | Math entity +랭크 | 수학적 용어(entity) --- | --- -0 | Scalar (magnitude only) -1 | Vector (magnitude and direction) -2 | Matrix (table of numbers) -3 | 3-Tensor (cube of numbers) -n | n-Tensor (you get the idea) +0 | 스칼라(Scalar) (크기(magnitude)만) +1 | 벡터(Vector) (크기와 방향(direction)) +2 | 행렬(Matrix) (숫자 표) +3 | 3-텐서 (숫자 큐브(cube)) +n | n-텐서 (you get the idea) -### Rank 0 +### 랭크 0 -The following snippet demonstrates creating a few rank 0 variables: +다음 일부 랭크 0 변수 생성 예입니다: ```python mammal = tf.Variable("Elephant", tf.string) @@ -62,13 +61,13 @@ floating = tf.Variable(3.14159265359, tf.float64) its_complicated = tf.Variable(12.3 - 4.85j, tf.complex64) ``` -Note: A string is treated as a single object in TensorFlow, not as a sequence of -characters. It is possible to have scalar strings, vectors of strings, etc. +Note: 문자열은 텐서에서 문자 시퀀스(sequence)가 아니라 단일 객체로 다뤄집니다. +객체는 단일 문자열과 문자열 벡터 등 모두 가능합니다. -### Rank 1 +### 랭크 1 -To create a rank 1 `tf.Tensor` object, you can pass a list of items as the -initial value. For example: +랭크 1 `tf.Tensor` 객체를 생성하기 위해서 초기값으로 아이템 리스트를 사용할 수 있습니다. +예를 들어: ```python mystr = tf.Variable(["Hello"], tf.string) @@ -78,10 +77,9 @@ its_very_complicated = tf.Variable([12.3 - 4.85j, 7.5 - 6.23j], tf.complex64) ``` -### Higher ranks +### 고차원 랭크 -A rank 2 `tf.Tensor` object consists of at least one row and at least -one column: +랭크 2 `tf.Tensor` 객체는 최소 한 개 이상의 열(column)과 행(row)으로 구성됩니다: ```python mymat = tf.Variable([[7],[11]], tf.int16) @@ -92,45 +90,41 @@ rank_of_squares = tf.rank(squarish_squares) mymatC = tf.Variable([[7],[11]], tf.int32) ``` -Higher-rank Tensors, similarly, consist of an n-dimensional array. For example, -during image processing, many tensors of rank 4 are used, with dimensions -corresponding to example-in-batch, image height, image width, and color channel. +유사하게 고차원 랭크 텐서는 n-차원 배열로 구성됩니다. +예를 들어, 이미지 처리에서 각각 배치 수와 이미지 높이, 이미지 너비, 색상 채널에 해당하는 4차원 랭크 텐서가 사용됩니다. ``` python -my_image = tf.zeros([10, 299, 299, 3]) # batch x height x width x color +my_image = tf.zeros([10, 299, 299, 3]) # 배치 x 높이 x 너비 x 색상 ``` -### Getting a `tf.Tensor` object's rank +### `tf.Tensor` 객체 랭크 구하기 -To determine the rank of a `tf.Tensor` object, call the `tf.rank` method. -For example, the following method programmatically determines the rank -of the `tf.Tensor` defined in the previous section: +`tf.Tensor` 객체의 랭크를 알기 위해서는 `tf.rank` 메서드를 호출합니다. +예를 들어, 다음 메서드는 프로그램적으로 이전 섹션에서 정의된 `tf.Tensor`의 랭크를 알려줍니다. ```python r = tf.rank(my_image) -# After the graph runs, r will hold the value 4. +# 그래프가 실행된 후 r은 4라는 값을 가지게 됩니다. ``` -### Referring to `tf.Tensor` slices +### `tf.Tensor` 일부분 참조하기 -Since a `tf.Tensor` is an n-dimensional array of cells, to access a single cell -in a `tf.Tensor` you need to specify n indices. +`tf.Tensor`는 n-차원 배열로 구성된 셀이기 대문에, +`tf.Tensor`의 셀 하나에 접근하기 위해서는 n개의 인덱스가 필요합니다. -For a rank 0 tensor (a scalar), no indices are necessary, since it is already a -single number. +랭크 0 텐서(스칼라)인 경우 그것이 이미 하나의 숫자이기 때문에 인덱스가 필요없습니다. -For a rank 1 tensor (a vector), passing a single index allows you to access a -number: +랭크 1 텐서(벡터)인 경우 숫자 하나에 접근하기 위해서는 인덱스 한 개를 전달해야 합니다: ```python my_scalar = my_vector[2] ``` -Note that the index passed inside the `[]` can itself be a scalar `tf.Tensor`, if -you want to dynamically choose an element from the vector. +벡터로부터 값 한 개를 동적으로 선택하기 위해서 +`[]`안에 스칼라형 `tf.Tensor`를 인덱스로 사용할 수 있습니다. -For tensors of rank 2 or higher, the situation is more interesting. For a -`tf.Tensor` of rank 2, passing two numbers returns a scalar, as expected: +랭크 2이상의 고차원 텐서인 경우에는 좀 더 흥미롭습니다. +예상한 것처럼 랭크 2인 `tf.Tensor`를 위해 인덱스로 2개를 전달해야 스칼라 한 개를 반환합니다: ```python @@ -138,7 +132,7 @@ my_scalar = my_matrix[1, 2] ``` -Passing a single number, however, returns a subvector of a matrix, as follows: +그러나, 한 개만 전달한다면 다음과 같이 행렬의 부분 벡터를 반환합니다: ```python @@ -146,9 +140,8 @@ my_row_vector = my_matrix[2] my_column_vector = my_matrix[:, 3] ``` -The `:` notation is python slicing syntax for "leave this dimension alone". This -is useful in higher-rank Tensors, as it allows you to access its subvectors, -submatrices, and even other subtensors. +`:` 표기는 "해당 차원를 남겨라"라는 파이썬 슬라이싱(slicing) 문법입니다. +이러한 표기법은 고차원 텐서에서 부분 벡터와 부분 행렬, 다른 부분 텐서들까지도 접근할 수 있도록 만들어 주기 때문에 유용합니다. ## Shape From 7b9a7f95c7f14ba1c9c14134406c52e3c03e458c Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Wed, 2 Oct 2019 14:04:54 +0900 Subject: [PATCH 04/13] KO: translate section 'Shape' --- site/ko/guide/tensor.md | 94 +++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 50 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index 1b6ee46664f..d7c34507e13 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -144,75 +144,69 @@ my_column_vector = my_matrix[:, 3] 이러한 표기법은 고차원 텐서에서 부분 벡터와 부분 행렬, 다른 부분 텐서들까지도 접근할 수 있도록 만들어 주기 때문에 유용합니다. -## Shape +## 쉐이프(Shape) -The **shape** of a tensor is the number of elements in each dimension. -TensorFlow automatically infers shapes during graph construction. These inferred -shapes might have known or unknown rank. If the rank is known, the sizes of each -dimension might be known or unknown. +텐서의 **쉐이프**는 각 차원에 있는 원소 개수입니다. +텐서플로는 그래프 계산 과정에서 자동으로 쉐이프를 추론합니다. +이렇게 추론된 쉐이프는 랭크를 알고 있는 경우도 있고 그렇지 않는 경우도 있습니다. +만약에 랭크를 알고 있는 경우라도 각 차원의 개수를 알고 경우도 있고 그렇지 않는 경우도 있습니다. -The TensorFlow documentation uses three notational conventions to describe -tensor dimensionality: rank, shape, and dimension number. The following table -shows how these relate to one another: +텐서플로 문서에서 텐서 차원을 표현하기 위해서 3가지 용어를 사용합니다: 랭크, 쉐이프, 차원수. +다음 표는 각 용어가 다른 용어와 연관되어 있는지를 보여줍니다. -Rank | Shape | Dimension number | Example +랭크 | 쉐이프 | 차원수 | 예제 --- | --- | --- | --- -0 | [] | 0-D | A 0-D tensor. A scalar. -1 | [D0] | 1-D | A 1-D tensor with shape [5]. -2 | [D0, D1] | 2-D | A 2-D tensor with shape [3, 4]. -3 | [D0, D1, D2] | 3-D | A 3-D tensor with shape [1, 4, 3]. -n | [D0, D1, ... Dn-1] | n-D | A tensor with shape [D0, D1, ... Dn-1]. +0 | [] | 0-D | 스칼라인 0-D 텐서. +1 | [D0] | 1-D | 쉐이프 [5]인 1-D 텐서. +2 | [D0, D1] | 2-D | 쉐이프 [3, 4]인 2-D 텐서. +3 | [D0, D1, D2] | 3-D | 쉐이프 [1, 4, 3]인 3-D 텐서. +n | [D0, D1, ... Dn-1] | n-D | 쉐이프 [D0, D1, ... Dn-1]인 텐서. -Shapes can be represented via Python lists / tuples of ints, or with the -`tf.TensorShape`. +쉐이프는 파이썬 리스트 / 정수형 튜플 또는 `tf.TensorShape`으로 표현될 수 있습니다. -### Getting a `tf.Tensor` object's shape +### `tf.Tensor` 객체 쉐이프 얻기 -There are two ways of accessing the shape of a `tf.Tensor`. While building the -graph, it is often useful to ask what is already known about a tensor's -shape. This can be done by reading the `shape` property of a `tf.Tensor` object. -This method returns a `TensorShape` object, which is a convenient way of -representing partially-specified shapes (since, when building the graph, not all -shapes will be fully known). +`tf.Tensor`의 쉐이프를 알기 위한 2가지 방법이 있습니다. +그래프를 생성하는 동안 텐서의 쉐이프를 알 수 있는 것은 종종 유용합니다. +쉐이프는 `tf.Tensor`객체의 `shape` 속성으로 알 수 있습니다. +이 메서드는 `TensorShape`를 반환하고, 이러한 방식은 완벽하게 알려지지 않는 쉐이프를 표현하는데 편리한 방법입니다 +(그래프를 생성할 때 모든 쉐이프를 알 수 없기 때문에). -It is also possible to get a `tf.Tensor` that will represent the fully-defined -shape of another `tf.Tensor` at runtime. This is done by calling the `tf.shape` -operation. This way, you can build a graph that manipulates the shapes of -tensors by building other tensors that depend on the dynamic shape of the input -`tf.Tensor`. +`tf.Tensor`를 얻는 것은 실행 시점에 쉐이프를 알고 있는 다른 `tf.Tensor`로 표현할 수 있습니다. +이것은 `tf.shape` 연산을 통해서 확인할 수 있습니다. +이를 통해, 입력 `tf.Tensor`의 동적인 쉐이프에 연동된 다른 텐서를 생성함으로써 +텐서 쉐이프를 변경하는 그래프를 생성할 수 있습니다. -For example, here is how to make a vector of zeros with the same size as the -number of columns in a given matrix: +예를 들어 다음은 주어진 행렬의 열 개수와 동일한 크기의 0으로 구성된 벡터를 만드는 예입니다. ``` python zeros = tf.zeros(my_matrix.shape[1]) ``` -### Changing the shape of a `tf.Tensor` +### `tf.Tensor` 쉐이프 변경 -The **number of elements** of a tensor is the product of the sizes of all its -shapes. The number of elements of a scalar is always `1`. Since there are often -many different shapes that have the same number of elements, it's often -convenient to be able to change the shape of a `tf.Tensor`, keeping its elements -fixed. This can be done with `tf.reshape`. +텐서의 **원소 개수**는 모든 쉐이프 크기를 곱한 것입니다. +스칼라의 원소 개수는 항상 `1`입니다. +원소 개수가 같은 경우라도 쉐이프는 다양할 수 있기 때문에, 그 원소 개수를 유지하면서 `tf.Tensor`의 쉐이프를 변경할 수 있는 것은 유용합니다. +이것은 `tf.reshape`으로 처리할 수 있습니다. -The following examples demonstrate how to reshape tensors: +다음은 텐서 쉐이프를 변경하는 예입니다: ```python rank_three_tensor = tf.ones([3, 4, 5]) -matrix = tf.reshape(rank_three_tensor, [6, 10]) # Reshape existing content into - # a 6x10 matrix -matrixB = tf.reshape(matrix, [3, -1]) # Reshape existing content into a 3x20 - # matrix. -1 tells reshape to calculate - # the size of this dimension. -matrixAlt = tf.reshape(matrixB, [4, 3, -1]) # Reshape existing content into a - #4x3x5 tensor - -# Note that the number of elements of the reshaped Tensors has to match the -# original number of elements. Therefore, the following example generates an -# error because no possible value for the last dimension will match the number -# of elements. -yet_another = tf.reshape(matrixAlt, [13, 2, -1]) # ERROR! +matrix = tf.reshape(rank_three_tensor, [6, 10]) # 기존 내용을 6x10 행렬로 + # 쉐이프 변경 +matrixB = tf.reshape(matrix, [3, -1]) # 기존 내용을 3x20 행렬로 쉐이프 변경 + # -1은 차원 크기를 계산한 후에 + # 쉐이프를 변경하라는 의미 +matrixAlt = tf.reshape(matrixB, [4, 3, -1]) # 기존 내용을 4x3x5 텐서로 + # 쉐이프 변경 + +# 쉐이프가 변경된 텐서의 원소 개수는 +# 원래 텐서의 원소 개수와 같습니다. +# 그러므로 다음은 원소 개수를 유지하면서 +# 마지막 차원에 사용 가능한 수가 없기 때문에 에러를 발생합니다. +yet_another = tf.reshape(matrixAlt, [13, 2, -1]) # 에러! ``` ## Data types From 85c70c9070ddbd908478bb200ff113fd95e00ab6 Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Wed, 2 Oct 2019 14:34:33 +0900 Subject: [PATCH 05/13] KO: translate section 'Data types' --- site/ko/guide/tensor.md | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index d7c34507e13..5287e4f50b7 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -209,30 +209,27 @@ matrixAlt = tf.reshape(matrixB, [4, 3, -1]) # 기존 내용을 4x3x5 텐서로 yet_another = tf.reshape(matrixAlt, [13, 2, -1]) # 에러! ``` -## Data types +## 데이터 타입(type) -In addition to dimensionality, Tensors have a data type. Refer to the -`tf.DType` page for a complete list of the data types. +차원뿐만 아니라, 텐서는 테이터 타입도 가지고 있습니다. +전체 데이터 타입을 확인하려면 `tf.DType`를 참고하세요. -It is not possible to have a `tf.Tensor` with more than one data type. It is -possible, however, to serialize arbitrary data structures as `string`s and store -those in `tf.Tensor`s. +`tf.Tensor`가 한 개이상의 데이터 타입을 가지는 것은 불가능합니다. +임의의 데이터 구조를 직렬화한 `string`를 저장한 `tf.Tensor`는 예외입니다. -It is possible to cast `tf.Tensor`s from one datatype to another using -`tf.cast`: +`tf.cast`를 이용해서 `tf.Tensor`의 데이터 타입을 다른 것으로 변경하는 것은 가능합니다: ``` python -# Cast a constant integer tensor into floating point. +# 정수형 텐서를 실수형으로 변환. float_tensor = tf.cast(tf.constant([1, 2, 3]), dtype=tf.float32) ``` -To inspect a `tf.Tensor`'s data type use the `Tensor.dtype` property. +`tf.Tensor`의 데이터 타입을 확인하기 위해서는 `Tensor.dtype` 속성을 활용하세요. -When creating a `tf.Tensor` from a python object you may optionally specify the -datatype. If you don't, TensorFlow chooses a datatype that can represent your -data. TensorFlow converts Python integers to `tf.int32` and python floating -point numbers to `tf.float32`. Otherwise TensorFlow uses the same rules numpy -uses when converting to arrays. +파이썬 객체를 이용해서 `tf.Tensor`를 생성할 때 데이터 타입을 선택적으로 명시할 수 있습니다. +그렇지 않으면 텐서플로가 데이터 표현에 적합한 데이터 타입을 선택합니다. +텐서플로는 파이썬 정수를 `tf.int32`로 변환하고 파이썬 실수는 `tf.float32`으로 변환합니다. +그외에 동일한 규칙을 numpy를 배열로 변경할 때 사용합니다. ## Evaluate tensors From e036b41d51ca6463554dabf5c452aa031af2d7b9 Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Wed, 2 Oct 2019 15:42:40 +0900 Subject: [PATCH 06/13] KO: translate section 'Evaluate tensors' --- site/ko/guide/tensor.md | 43 ++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index 5287e4f50b7..697654f2056 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -231,15 +231,12 @@ float_tensor = tf.cast(tf.constant([1, 2, 3]), dtype=tf.float32) 텐서플로는 파이썬 정수를 `tf.int32`로 변환하고 파이썬 실수는 `tf.float32`으로 변환합니다. 그외에 동일한 규칙을 numpy를 배열로 변경할 때 사용합니다. -## Evaluate tensors +## 텐서 계산하기(evaluate) -Once the computation graph has been built, you can run the computation that -produces a particular `tf.Tensor` and fetch the value assigned to it. This is -often useful for debugging as well as being required for much of TensorFlow to -work. +일단 계산 그래프를 만들었다면, 특정 `tf.Tensor`를 생성하고 그것에 지정된 값을 가져오는 계산을 실행할 수 있습니다. +이것은 대부분의 텐서플로가 작업하는데 필요할 뿐 아니라 디버깅에 종종 유용합니다. -The simplest way to evaluate a Tensor is using the `Tensor.eval` method. For -example: +텐서를 계산하는 가장 간단한 방법은 `Tensor.eval` 메서드를 사용하는 것입니다. 예를 들어: ```python constant = tf.constant([1, 2, 3]) @@ -247,32 +244,30 @@ tensor = constant * constant print(tensor.eval()) ``` -The `eval` method only works when a default `tf.Session` is active (see -[Graphs and Sessions](./graphs.md) for more information). +`eval` 메서드는 기본 `tf.Session`이 활성화된 경우에만 작동합니다 +(자세한 내용은 [그래프와 세션](./graphs.md)에서 확인하세요). -`Tensor.eval` returns a numpy array with the same contents as the tensor. +`Tensor.eval`은 텐서와 같은 내용을 가지는 numpy 배열을 반환합니다. -Sometimes it is not possible to evaluate a `tf.Tensor` with no context because -its value might depend on dynamic information that is not available. For -example, tensors that depend on `placeholder`s can't be evaluated without -providing a value for the `placeholder`. +때때로 그 값이 이용할 수 없는 동적인 정보에 의존하기 때문에 +문맥(context)이 없는 `tf.Tensor`는 계산할 수 없는 경우가 있습니다. +예를 들어, `placeholder`인 텐서는 그 `placeholder`에 해당하는 값이 제공되지 않으면 계산할 수 없습니다. ``` python p = tf.placeholder(tf.float32) t = p + 1.0 -t.eval() # This will fail, since the placeholder did not get a value. -t.eval(feed_dict={p:2.0}) # This will succeed because we're feeding a value - # to the placeholder. +t.eval() # 플레이스홀더(placeholder)가 값을 가지고 있지 않기 때문에, 이것은 실패할 것입니다. +t.eval(feed_dict={p:2.0}) # 플레이스홀더에 해당하는 값을 제공받기 때문에 + # 이것은 성공할 것입니다. ``` -Note that it is possible to feed any `tf.Tensor`, not just placeholders. +플레이스홀더뿐만 아니라 어떤 `tf.Tensor`도 값을 제공받는 것이 가능하다는 것에 유의하세요. -Other model constructs might make evaluating a `tf.Tensor` -complicated. TensorFlow can't directly evaluate `tf.Tensor`s defined inside -functions or inside control flow constructs. If a `tf.Tensor` depends on a value -from a queue, evaluating the `tf.Tensor` will only work once something has been -enqueued; otherwise, evaluating it will hang. When working with queues, remember -to call `tf.train.start_queue_runners` before evaluating any `tf.Tensor`s. +다른 모델 구조는 `tf.Tensor`를 계산하는 것을 복잡하게 만들 수 있습니다. +텐서플로는 함수안이나 제어 흐름안에 정의된 `tf.Tensor`를 직접 계산할 수 없습니다. +만약에 `tf.Tensor`가 큐(queue)에 있는 값을 사용한다면, +무언가가 큐에 들어간 후에 만 `tf.Tensor` 계산을 할 수 있습니다; 그렇지 않으면 계산은 중단될 것입니다. +큐와 같이 작업할 때, `tf.Tensor`를 계산하기 전 `tf.train.start_queue_runners`를 호출하세요. ## Print a tensor From 464b1db666a90314b5546c434f91ac1e1edcfcb4 Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Wed, 2 Oct 2019 16:33:28 +0900 Subject: [PATCH 07/13] KO: translate section 'Print a tensor' --- site/ko/guide/tensor.md | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index 697654f2056..4e501ba717e 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -269,36 +269,33 @@ t.eval(feed_dict={p:2.0}) # 플레이스홀더에 해당하는 값을 제공받 무언가가 큐에 들어간 후에 만 `tf.Tensor` 계산을 할 수 있습니다; 그렇지 않으면 계산은 중단될 것입니다. 큐와 같이 작업할 때, `tf.Tensor`를 계산하기 전 `tf.train.start_queue_runners`를 호출하세요. -## Print a tensor +## 텐서 출력하기 -For debugging purposes you might want to print the value of a `tf.Tensor`. While - [tfdbg](../guide/debugger.md) provides advanced debugging support, TensorFlow also has an - operation to directly print the value of a `tf.Tensor`. +디버깅을 위해서 `tf.Tensor` 값을 출력하고 싶을 것입니다. +[tfdbg](../guide/debugger.md)에서 고급 디버깅에 관해 제공하지만, +텐서플로는 `tf.Tensor`값을 직접 출력할 수 있는 연산자를 가지고 있습니다. -Note that you rarely want to use the following pattern when printing a -`tf.Tensor`: +`tf.Tensor`를 출력할 때 다음과 같은 패턴을 쓰고자 하는 경우는 거의 없습니다: ``` python t = <> -print(t) # This will print the symbolic tensor when the graph is being built. - # This tensor does not have a value in this context. +print(t) # 이것은 그래프가 생성되어질 때 기호화된 텐서(symbolic tensor)를 출력할 것입니다. + # 이 텐서는 이 컨텍스트(context)안에서 값을 가지고 있지 않습니다. ``` -This code prints the `tf.Tensor` object (which represents deferred computation) -and not its value. Instead, TensorFlow provides the `tf.Print` operation, which -returns its first tensor argument unchanged while printing the set of -`tf.Tensor`s it is passed as the second argument. +이 코드는 `tf.Tensor`의 값이 아닌 객체(지연 계산으로 표현)를 출력합니다. +실제로 텐서플로는 두번째 인수로 전달된 `tf.Tensor` 집합을 출력하는 동안 +변경되지 않는 첫번째 텐서 인수를 반환하는 `tf.Print` 연산을 제공합니다. -To correctly use `tf.Print` its return value must be used. See the example below +`tf.Print`을 제대로 사용하기 위해서는 반환된 값을 사용해야 합니다. 아래 예를 보면 ``` python t = <> -tf.Print(t, [t]) # This does nothing -t = tf.Print(t, [t]) # Here we are using the value returned by tf.Print -result = t + 1 # Now when result is evaluated the value of `t` will be printed. +tf.Print(t, [t]) # 어떤 일도 하지 않습니다 +t = tf.Print(t, [t]) # 여기서 tf.Print에 의해 반환된 값을 사용할 수 있습니다. +result = t + 1 # 이제 결과를 계산할 때 `t` 값이 출력될 것입니다. ``` -When you evaluate `result` you will evaluate everything `result` depends -upon. Since `result` depends upon `t`, and evaluating `t` has the side effect of -printing its input (the old value of `t`), `t` gets printed. +`result`를 계산할 때 `result`이 관련된 모든 것이 계산될 것입니다. +`result`는 `t`와 의존성이 있고, `t`를 계산하는 것이 그 입력(`t`의 이전 값)을 출력하는 부가 효과가 있기 때문에 `t`는 출력됩니다. From e390e1e23b4573606da5b0af27adf1e416a1d265 Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Wed, 2 Oct 2019 17:43:36 +0900 Subject: [PATCH 08/13] KO: fix typo and misused words --- site/ko/guide/tensor.md | 80 +++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index 4e501ba717e..321fe0b828f 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -1,24 +1,25 @@ # 텐서플로 텐서 이름에서 알 수 있듯이, 텐서플로는 텐서를 포함한 계산을 정의하고 실행하는 프레임워크입니다. -*텐서*는 벡터와 행렬을 일반화한 것이고 고차원으로 확장가능합니다. -내부적으로 텐서플로는 텐서를 n-차원의 기본 데이터형식의 배열로 표현합니다. +*텐서*는 벡터(vector)와 행렬(matrix)을 일반화한 것이고 고차원으로 확장 가능합니다. +내부적으로 텐서플로는 텐서를 기본 데이터 타입의 n-차원 배열로 나타냅니다. -텐서플로 프로그램을 작성할 때, 조작하고 전달하는 중요 객체는 `tf.Tensor`입니다. -`tf.Tensor` 객체는 부분적으로 결과적으로는 값으로 변환될 수 있는 계산으로 표현됩니다. -텐서플로 프로그램은 `tf.Tensor` 객체 그래프를 먼저 만드는 것으로 시작하고, -각가의 텐서가 다른 텐서를 기반으로 어떤식으로 계산될 수 있는지 구체화하고, -그 다음 그래프를 실행하서 원하는 결과를 얻게 됩니다. +텐서플로 프로그램을 작성할 때, 조작하고 전달하는 중요 객체는 `tf.Tensor` 입니다. +`tf.Tensor` 객체는 결과적으로는 값으로 변환될 수 있는 부분적으로 정의된 계산으로 표현됩니다. +텐서플로 프로그램은 `tf.Tensor` 객체 그래프를 만드는 것으로 먼저 시작하고, +각각의 텐서가 다른 텐서를 기반으로 어떤 식으로 계산될 수 있는지 구체화하고, +그 다음 그래프를 실행해서 원하는 결과를 얻게 됩니다. `tf.Tensor`는 다음과 같은 속성을 가지고 있습니다: - * 데이터 타입 (예를 들어, `float32` 또는 `int32`, `string`) - * 모양(shape) + * 데이터 타입(data type) (예를 들어, `float32` 또는 `int32`, `string`) + * 쉐이프(shape) -텐서안의 각각 요소(element)는 동일한 데이터 타입이고 항상 그 데이터 타입을 알 수 있습니다. -모양(즉, 차원 크기와 각 차원마다 길이(size))는 일부만 알 수 있습니다. -대부분 연산은 입력값 모양을 알 수 있다면 모든 정보를 알 수 있는 텐서를 만들지만, -일부 경우에서는 그래프를 실행한 이후에 텐서 모양을 알 수 있기도 합니다. + +텐서안의 각각 원소(element)는 동일한 데이터 타입이고 항상 그 데이터 타입을 알 수 있습니다. +쉐이프(즉, 차원 수와 각 차원마다 길이(size))는 일부만 알 수 있습니다. +대부분 연산은 입력값 쉐이프를 알 수 있다면 모든 정보를 알 수 있는 텐서를 만들지만, +일부 경우에서는 그래프를 실행한 이후에 텐서 쉐이프를 알 수 있기도 합니다. 일부 특별한 텐서는 텐서플로 가이드문서의 다른 부분에서 다뤄질 것입니다. 핵심인 텐서는 다음과 같습니다: @@ -28,10 +29,10 @@ * `tf.placeholder` * `tf.SparseTensor` -예외인 `tf.Variable`을 제외한다면, 텐서 값은 변경불가능(immutable) 합니다. -즉, 텐서를 한번만 실행시킨 경우에는 오직 하나의 값만을 가집니다. -그러나, 동일한 텐서를 다시 실행시킨다면 다른 값을 가질 수 있습니다: -예를 들어 텐서가 디스크로부터 데이터를 읽어들인 결과 이거나, +예외인 `tf.Variable`을 제외한다면, 텐서 값은 변경불가능(immutable)합니다. +즉, 텐서를 한번 실행시킨 경우에는 오직 하나의 값만을 가집니다. +그러나, 동일한 텐서를 다시 실행시킨다면 다른 값을 가질 수 있습니다; +예를 들어 텐서가 디스크로부터 데이터를 읽어들인 결과이거나, 무작위 숫자를 생성하는 경우입니다. ## 랭크(Rank) @@ -39,23 +40,23 @@ `tf.Tensor` 객체의 **랭크**는 그 차원의 수입니다. 랭크의 동의어는 **order** 또는 **degree**, **n-차원**입니다. 텐서플로의 랭크는 수학에서 사용하는 행렬의 랭크와는 다릅니다. -다음 표에서 알 수 있는 것처럼, 텐서플로의 각 랭크는 각각 다른 수학적 용어(entity)에 해당됩니다. +다음 표에서 알 수 있는 것처럼, 텐서플로의 각 랭크는 각각 다른 수학 개체(entity)에 해당됩니다. -랭크 | 수학적 용어(entity) +랭크 | 수학 개체(entity) --- | --- 0 | 스칼라(Scalar) (크기(magnitude)만) 1 | 벡터(Vector) (크기와 방향(direction)) 2 | 행렬(Matrix) (숫자 표) 3 | 3-텐서 (숫자 큐브(cube)) -n | n-텐서 (you get the idea) +n | n-텐서 (알 수 있을겁니다(you get the idea)) ### 랭크 0 -다음 일부 랭크 0 변수 생성 예입니다: +다음은 랭크 0 변수 생성 예의 일부입니다: ```python -mammal = tf.Variable("Elephant", tf.string) +mammal = tf.Variable("코끼리", tf.string) ignition = tf.Variable(451, tf.int16) floating = tf.Variable(3.14159265359, tf.float64) its_complicated = tf.Variable(12.3 - 4.85j, tf.complex64) @@ -66,11 +67,11 @@ Note: 문자열은 텐서에서 문자 시퀀스(sequence)가 아니라 단일 ### 랭크 1 -랭크 1 `tf.Tensor` 객체를 생성하기 위해서 초기값으로 아이템 리스트를 사용할 수 있습니다. +랭크 1 `tf.Tensor` 객체를 생성하기 위해서 초기값으로 리스트를 사용할 수 있습니다. 예를 들어: ```python -mystr = tf.Variable(["Hello"], tf.string) +mystr = tf.Variable(["안녕하세요"], tf.string) cool_numbers = tf.Variable([3.14159, 2.71828], tf.float32) first_primes = tf.Variable([2, 3, 5, 7, 11], tf.int32) its_very_complicated = tf.Variable([12.3 - 4.85j, 7.5 - 6.23j], tf.complex64) @@ -90,8 +91,8 @@ rank_of_squares = tf.rank(squarish_squares) mymatC = tf.Variable([[7],[11]], tf.int32) ``` -유사하게 고차원 랭크 텐서는 n-차원 배열로 구성됩니다. -예를 들어, 이미지 처리에서 각각 배치 수와 이미지 높이, 이미지 너비, 색상 채널에 해당하는 4차원 랭크 텐서가 사용됩니다. +유사하게, 고차원 랭크 텐서는 n-차원 배열로 구성됩니다. +예를 들어, 이미지 처리에서는 각각 배치 수와 이미지 높이, 이미지 너비, 색상 채널에 해당하는 4차원 랭크 텐서가 사용됩니다. ``` python my_image = tf.zeros([10, 299, 299, 3]) # 배치 x 높이 x 너비 x 색상 @@ -107,9 +108,9 @@ r = tf.rank(my_image) # 그래프가 실행된 후 r은 4라는 값을 가지게 됩니다. ``` -### `tf.Tensor` 일부분 참조하기 +### `tf.Tensor` 일부분(slice) 참조하기 -`tf.Tensor`는 n-차원 배열로 구성된 셀이기 대문에, +`tf.Tensor`는 n-차원 배열로 구성된 셀이기 때문에, `tf.Tensor`의 셀 하나에 접근하기 위해서는 n개의 인덱스가 필요합니다. 랭크 0 텐서(스칼라)인 경우 그것이 이미 하나의 숫자이기 때문에 인덱스가 필요없습니다. @@ -120,7 +121,7 @@ r = tf.rank(my_image) my_scalar = my_vector[2] ``` -벡터로부터 값 한 개를 동적으로 선택하기 위해서 +벡터로부터 원소 한 개를 동적으로 선택하기 위해서 `[]`안에 스칼라형 `tf.Tensor`를 인덱스로 사용할 수 있습니다. 랭크 2이상의 고차원 텐서인 경우에는 좀 더 흥미롭습니다. @@ -156,11 +157,11 @@ my_column_vector = my_matrix[:, 3] 랭크 | 쉐이프 | 차원수 | 예제 --- | --- | --- | --- -0 | [] | 0-D | 스칼라인 0-D 텐서. -1 | [D0] | 1-D | 쉐이프 [5]인 1-D 텐서. -2 | [D0, D1] | 2-D | 쉐이프 [3, 4]인 2-D 텐서. -3 | [D0, D1, D2] | 3-D | 쉐이프 [1, 4, 3]인 3-D 텐서. -n | [D0, D1, ... Dn-1] | n-D | 쉐이프 [D0, D1, ... Dn-1]인 텐서. +0 | [] | 0-차원 | 스칼라인 0-차원 텐서. +1 | [D0] | 1-차원 | 쉐이프 [5]인 1-차원 텐서. +2 | [D0, D1] | 2-차원 | 쉐이프 [3, 4]인 2-차원 텐서. +3 | [D0, D1, D2] | 3-차원 | 쉐이프 [1, 4, 3]인 3-차원 텐서. +n | [D0, D1, ... Dn-1] | n-차원 | 쉐이프 [D0, D1, ... Dn-1]인 텐서. 쉐이프는 파이썬 리스트 / 정수형 튜플 또는 `tf.TensorShape`으로 표현될 수 있습니다. @@ -169,7 +170,7 @@ n | [D0, D1, ... Dn-1] | n-D | 쉐이프 [D0, D1, ... Dn-1]인 텐서. `tf.Tensor`의 쉐이프를 알기 위한 2가지 방법이 있습니다. 그래프를 생성하는 동안 텐서의 쉐이프를 알 수 있는 것은 종종 유용합니다. 쉐이프는 `tf.Tensor`객체의 `shape` 속성으로 알 수 있습니다. -이 메서드는 `TensorShape`를 반환하고, 이러한 방식은 완벽하게 알려지지 않는 쉐이프를 표현하는데 편리한 방법입니다 +이 메서드는 `TensorShape`를 반환하고, 이러한 방식은 전체가 알려지지 않는 쉐이프를 표현하는데 편리한 방법입니다 (그래프를 생성할 때 모든 쉐이프를 알 수 없기 때문에). `tf.Tensor`를 얻는 것은 실행 시점에 쉐이프를 알고 있는 다른 `tf.Tensor`로 표현할 수 있습니다. @@ -185,9 +186,10 @@ zeros = tf.zeros(my_matrix.shape[1]) ### `tf.Tensor` 쉐이프 변경 -텐서의 **원소 개수**는 모든 쉐이프 크기를 곱한 것입니다. +텐서의 **원소 개수**는 모든 쉐이프의 크기를 곱한 것입니다. 스칼라의 원소 개수는 항상 `1`입니다. -원소 개수가 같은 경우라도 쉐이프는 다양할 수 있기 때문에, 그 원소 개수를 유지하면서 `tf.Tensor`의 쉐이프를 변경할 수 있는 것은 유용합니다. +원소 개수가 같은 경우라도 쉐이프는 다양할 수 있기 때문에, +그 원소 개수를 유지하면서 `tf.Tensor`의 쉐이프를 변경할 수 있는 것은 유용합니다. 이것은 `tf.reshape`으로 처리할 수 있습니다. 다음은 텐서 쉐이프를 변경하는 예입니다: @@ -250,7 +252,7 @@ print(tensor.eval()) `Tensor.eval`은 텐서와 같은 내용을 가지는 numpy 배열을 반환합니다. 때때로 그 값이 이용할 수 없는 동적인 정보에 의존하기 때문에 -문맥(context)이 없는 `tf.Tensor`는 계산할 수 없는 경우가 있습니다. +컨텍스트(context)가 없는 `tf.Tensor`는 계산할 수 없는 경우가 있습니다. 예를 들어, `placeholder`인 텐서는 그 `placeholder`에 해당하는 값이 제공되지 않으면 계산할 수 없습니다. ``` python @@ -272,7 +274,7 @@ t.eval(feed_dict={p:2.0}) # 플레이스홀더에 해당하는 값을 제공받 ## 텐서 출력하기 디버깅을 위해서 `tf.Tensor` 값을 출력하고 싶을 것입니다. -[tfdbg](../guide/debugger.md)에서 고급 디버깅에 관해 제공하지만, +고급 디버깅에 대해 [tfdbg](../guide/debugger.md)에서 가이드를 제공하지만, 텐서플로는 `tf.Tensor`값을 직접 출력할 수 있는 연산자를 가지고 있습니다. `tf.Tensor`를 출력할 때 다음과 같은 패턴을 쓰고자 하는 경우는 거의 없습니다: From aa0a2a8f5c4bf481bfc0d265c56e259b42b70bd0 Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Mon, 14 Oct 2019 13:52:56 +0900 Subject: [PATCH 09/13] KO: revise doc after @JKIsaacLee's review --- site/ko/guide/tensor.md | 112 ++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index 321fe0b828f..02e1cc29aea 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -1,8 +1,8 @@ # 텐서플로 텐서 이름에서 알 수 있듯이, 텐서플로는 텐서를 포함한 계산을 정의하고 실행하는 프레임워크입니다. -*텐서*는 벡터(vector)와 행렬(matrix)을 일반화한 것이고 고차원으로 확장 가능합니다. -내부적으로 텐서플로는 텐서를 기본 데이터 타입의 n-차원 배열로 나타냅니다. +*텐서*는 벡터와 행렬을 일반화한 것이고 고차원으로 확장 가능합니다. +내부적으로 텐서플로는 텐서를 기본 변수형의 n-차원 배열로 나타냅니다. 텐서플로 프로그램을 작성할 때, 조작하고 전달하는 중요 객체는 `tf.Tensor` 입니다. `tf.Tensor` 객체는 결과적으로는 값으로 변환될 수 있는 부분적으로 정의된 계산으로 표현됩니다. @@ -12,14 +12,14 @@ `tf.Tensor`는 다음과 같은 속성을 가지고 있습니다: - * 데이터 타입(data type) (예를 들어, `float32` 또는 `int32`, `string`) - * 쉐이프(shape) + * 변수형 (예를 들어, `float32` 또는 `int32`, `string`) + * 형태 -텐서안의 각각 원소(element)는 동일한 데이터 타입이고 항상 그 데이터 타입을 알 수 있습니다. -쉐이프(즉, 차원 수와 각 차원마다 길이(size))는 일부만 알 수 있습니다. -대부분 연산은 입력값 쉐이프를 알 수 있다면 모든 정보를 알 수 있는 텐서를 만들지만, -일부 경우에서는 그래프를 실행한 이후에 텐서 쉐이프를 알 수 있기도 합니다. +텐서안의 각각 원소는 동일한 변수형이고 항상 그 변수형을 알 수 있습니다. +형태(즉, 차원 수와 각 차원마다 길이)는 일부만 알 수 있습니다. +대부분 연산은 입력값 형태를 알 수 있다면 모든 정보를 알 수 있는 텐서를 만들지만, +일부 경우에서는 그래프를 실행한 이후에 텐서 형태를 알 수 있기도 합니다. 일부 특별한 텐서는 텐서플로 가이드문서의 다른 부분에서 다뤄질 것입니다. 핵심인 텐서는 다음과 같습니다: @@ -29,7 +29,7 @@ * `tf.placeholder` * `tf.SparseTensor` -예외인 `tf.Variable`을 제외한다면, 텐서 값은 변경불가능(immutable)합니다. +예외인 `tf.Variable`을 제외한다면, 텐서 값은 변경할 수 없습니다. 즉, 텐서를 한번 실행시킨 경우에는 오직 하나의 값만을 가집니다. 그러나, 동일한 텐서를 다시 실행시킨다면 다른 값을 가질 수 있습니다; 예를 들어 텐서가 디스크로부터 데이터를 읽어들인 결과이거나, @@ -38,11 +38,11 @@ ## 랭크(Rank) `tf.Tensor` 객체의 **랭크**는 그 차원의 수입니다. -랭크의 동의어는 **order** 또는 **degree**, **n-차원**입니다. +랭크의 동의어는 **order** 또는 **degree**, **n-dimension**입니다. 텐서플로의 랭크는 수학에서 사용하는 행렬의 랭크와는 다릅니다. 다음 표에서 알 수 있는 것처럼, 텐서플로의 각 랭크는 각각 다른 수학 개체(entity)에 해당됩니다. -랭크 | 수학 개체(entity) +랭크 | 수학 개체 --- | --- 0 | 스칼라(Scalar) (크기(magnitude)만) 1 | 벡터(Vector) (크기와 방향(direction)) @@ -80,7 +80,7 @@ its_very_complicated = tf.Variable([12.3 - 4.85j, 7.5 - 6.23j], tf.complex64) ### 고차원 랭크 -랭크 2 `tf.Tensor` 객체는 최소 한 개 이상의 열(column)과 행(row)으로 구성됩니다: +랭크 2 `tf.Tensor` 객체는 최소 한 개 이상의 열과 행으로 구성됩니다: ```python mymat = tf.Variable([[7],[11]], tf.int16) @@ -101,7 +101,7 @@ my_image = tf.zeros([10, 299, 299, 3]) # 배치 x 높이 x 너비 x 색상 ### `tf.Tensor` 객체 랭크 구하기 `tf.Tensor` 객체의 랭크를 알기 위해서는 `tf.rank` 메서드를 호출합니다. -예를 들어, 다음 메서드는 프로그램적으로 이전 섹션에서 정의된 `tf.Tensor`의 랭크를 알려줍니다. +예를 들어, 다음 메서드는 이전 섹션에서 정의된 `tf.Tensor`의 랭크를 프로그래밍 방식으로 알려줍니다. ```python r = tf.rank(my_image) @@ -141,42 +141,42 @@ my_row_vector = my_matrix[2] my_column_vector = my_matrix[:, 3] ``` -`:` 표기는 "해당 차원를 남겨라"라는 파이썬 슬라이싱(slicing) 문법입니다. +`:` 표기는 "해당 차원을 남겨라"라는 파이썬 슬라이싱(slicing) 문법입니다. 이러한 표기법은 고차원 텐서에서 부분 벡터와 부분 행렬, 다른 부분 텐서들까지도 접근할 수 있도록 만들어 주기 때문에 유용합니다. -## 쉐이프(Shape) +## 형태 -텐서의 **쉐이프**는 각 차원에 있는 원소 개수입니다. -텐서플로는 그래프 계산 과정에서 자동으로 쉐이프를 추론합니다. -이렇게 추론된 쉐이프는 랭크를 알고 있는 경우도 있고 그렇지 않는 경우도 있습니다. -만약에 랭크를 알고 있는 경우라도 각 차원의 개수를 알고 경우도 있고 그렇지 않는 경우도 있습니다. +텐서의 **형태**는 각 차원에 있는 원소 개수로 표현됩니다. +텐서플로는 그래프 계산 과정에서 자동으로 텐서 형태를 추론합니다. +이렇게 추론된 형태는 랭크를 알고 있는 경우도 있고 그렇지 않는 경우도 있습니다. +만약에 랭크를 알고 있는 경우라도 각 차원의 원소 개수를 알고 있는 경우도 있고 그렇지 않는 경우도 있습니다. -텐서플로 문서에서 텐서 차원을 표현하기 위해서 3가지 용어를 사용합니다: 랭크, 쉐이프, 차원수. +텐서플로 문서에서 텐서 차원을 표현하기 위해서 3가지 용어를 사용합니다: 랭크, 형태, 차원. 다음 표는 각 용어가 다른 용어와 연관되어 있는지를 보여줍니다. -랭크 | 쉐이프 | 차원수 | 예제 +랭크 | 형태 | 차원 | 예제 --- | --- | --- | --- 0 | [] | 0-차원 | 스칼라인 0-차원 텐서. -1 | [D0] | 1-차원 | 쉐이프 [5]인 1-차원 텐서. -2 | [D0, D1] | 2-차원 | 쉐이프 [3, 4]인 2-차원 텐서. -3 | [D0, D1, D2] | 3-차원 | 쉐이프 [1, 4, 3]인 3-차원 텐서. -n | [D0, D1, ... Dn-1] | n-차원 | 쉐이프 [D0, D1, ... Dn-1]인 텐서. +1 | [D0] | 1-차원 | 형태가 [5]인 1-차원 텐서. +2 | [D0, D1] | 2-차원 | 형태가 [3, 4]인 2-차원 텐서. +3 | [D0, D1, D2] | 3-차원 | 형태가 [1, 4, 3]인 3-차원 텐서. +n | [D0, D1, ... Dn-1] | n-차원 | 형태가 [D0, D1, ... Dn-1]인 텐서. -쉐이프는 파이썬 리스트 / 정수형 튜플 또는 `tf.TensorShape`으로 표현될 수 있습니다. +형태는 파이썬 리스트 / 정수형 튜플 또는 `tf.TensorShape`으로 표현될 수 있습니다. -### `tf.Tensor` 객체 쉐이프 얻기 +### `tf.Tensor` 객체 형태 얻기 -`tf.Tensor`의 쉐이프를 알기 위한 2가지 방법이 있습니다. -그래프를 생성하는 동안 텐서의 쉐이프를 알 수 있는 것은 종종 유용합니다. -쉐이프는 `tf.Tensor`객체의 `shape` 속성으로 알 수 있습니다. -이 메서드는 `TensorShape`를 반환하고, 이러한 방식은 전체가 알려지지 않는 쉐이프를 표현하는데 편리한 방법입니다 -(그래프를 생성할 때 모든 쉐이프를 알 수 없기 때문에). +`tf.Tensor`의 형태를 알기 위한 2가지 방법이 있습니다. +그래프를 생성하는 동안 텐서의 형태를 알 수 있는 것은 종종 유용합니다. +형태는 `tf.Tensor`객체의 `shape` 속성으로 알 수 있습니다. +이 메서드는 `TensorShape`를 반환하고, 이러한 방식은 전체가 알려지지 않는 형태를 표현하는데 편리한 방법입니다 +(그래프를 생성할 때 모든 형태를 알 수 없기 때문에). -`tf.Tensor`를 얻는 것은 실행 시점에 쉐이프를 알고 있는 다른 `tf.Tensor`로 표현할 수 있습니다. +`tf.Tensor`를 얻는 것은 실행 시점에 형태를 알고 있는 다른 `tf.Tensor`로 표현할 수 있습니다. 이것은 `tf.shape` 연산을 통해서 확인할 수 있습니다. -이를 통해, 입력 `tf.Tensor`의 동적인 쉐이프에 연동된 다른 텐서를 생성함으로써 -텐서 쉐이프를 변경하는 그래프를 생성할 수 있습니다. +이를 통해, 입력 `tf.Tensor`의 동적인 형태에 연동된 다른 텐서를 생성함으로써 +텐서 형태를 변경하는 그래프를 생성할 수 있습니다. 예를 들어 다음은 주어진 행렬의 열 개수와 동일한 크기의 0으로 구성된 벡터를 만드는 예입니다. @@ -184,54 +184,54 @@ n | [D0, D1, ... Dn-1] | n-차원 | 쉐이프 [D0, D1, ... Dn-1]인 텐서. zeros = tf.zeros(my_matrix.shape[1]) ``` -### `tf.Tensor` 쉐이프 변경 +### `tf.Tensor` 형태 변경 -텐서의 **원소 개수**는 모든 쉐이프의 크기를 곱한 것입니다. +텐서의 **원소 개수**는 모든 형태의 크기를 곱한 것입니다. 스칼라의 원소 개수는 항상 `1`입니다. -원소 개수가 같은 경우라도 쉐이프는 다양할 수 있기 때문에, -그 원소 개수를 유지하면서 `tf.Tensor`의 쉐이프를 변경할 수 있는 것은 유용합니다. +원소 개수가 같은 경우에도 형태는 다양할 수 있기 때문에, +그 원소 개수를 유지하면서 `tf.Tensor`의 형태를 변경할 수 있는 것은 유용합니다. 이것은 `tf.reshape`으로 처리할 수 있습니다. -다음은 텐서 쉐이프를 변경하는 예입니다: +다음은 텐서 형태를 변경하는 예입니다: ```python rank_three_tensor = tf.ones([3, 4, 5]) matrix = tf.reshape(rank_three_tensor, [6, 10]) # 기존 내용을 6x10 행렬로 - # 쉐이프 변경 -matrixB = tf.reshape(matrix, [3, -1]) # 기존 내용을 3x20 행렬로 쉐이프 변경 + # 형태 변경 +matrixB = tf.reshape(matrix, [3, -1]) # 기존 내용을 3x20 행렬로 형태 변경 # -1은 차원 크기를 계산한 후에 - # 쉐이프를 변경하라는 의미 + # 형태를 변경하라는 의미 matrixAlt = tf.reshape(matrixB, [4, 3, -1]) # 기존 내용을 4x3x5 텐서로 - # 쉐이프 변경 + # 형태 변경 -# 쉐이프가 변경된 텐서의 원소 개수는 +# 형태가 변경된 텐서의 원소 개수는 # 원래 텐서의 원소 개수와 같습니다. # 그러므로 다음은 원소 개수를 유지하면서 # 마지막 차원에 사용 가능한 수가 없기 때문에 에러를 발생합니다. yet_another = tf.reshape(matrixAlt, [13, 2, -1]) # 에러! ``` -## 데이터 타입(type) +## 변수형 -차원뿐만 아니라, 텐서는 테이터 타입도 가지고 있습니다. -전체 데이터 타입을 확인하려면 `tf.DType`를 참고하세요. +차원뿐만 아니라, 텐서는 변수형도 가지고 있습니다. +전체 변수형을 확인하려면 `tf.DType`를 참고하세요. -`tf.Tensor`가 한 개이상의 데이터 타입을 가지는 것은 불가능합니다. +`tf.Tensor`가 한 개이상의 변수형을 가지는 것은 불가능합니다. 임의의 데이터 구조를 직렬화한 `string`를 저장한 `tf.Tensor`는 예외입니다. -`tf.cast`를 이용해서 `tf.Tensor`의 데이터 타입을 다른 것으로 변경하는 것은 가능합니다: +`tf.cast`를 이용해서 `tf.Tensor`의 변수형을 다른 것으로 변경하는 것은 가능합니다: ``` python # 정수형 텐서를 실수형으로 변환. float_tensor = tf.cast(tf.constant([1, 2, 3]), dtype=tf.float32) ``` -`tf.Tensor`의 데이터 타입을 확인하기 위해서는 `Tensor.dtype` 속성을 활용하세요. +`tf.Tensor`의 변수형을 확인하기 위해서는 `Tensor.dtype` 속성을 활용하세요. -파이썬 객체를 이용해서 `tf.Tensor`를 생성할 때 데이터 타입을 선택적으로 명시할 수 있습니다. -그렇지 않으면 텐서플로가 데이터 표현에 적합한 데이터 타입을 선택합니다. +파이썬 객체를 이용해서 `tf.Tensor`를 생성할 때 변수형을 선택적으로 명시할 수 있습니다. +그렇지 않으면 텐서플로가 데이터 표현에 적합한 변수형을 선택합니다. 텐서플로는 파이썬 정수를 `tf.int32`로 변환하고 파이썬 실수는 `tf.float32`으로 변환합니다. -그외에 동일한 규칙을 numpy를 배열로 변경할 때 사용합니다. +그외에 동일한 규칙을 넘파이(numpy)를 배열로 변경할 때 사용합니다. ## 텐서 계산하기(evaluate) @@ -249,7 +249,7 @@ print(tensor.eval()) `eval` 메서드는 기본 `tf.Session`이 활성화된 경우에만 작동합니다 (자세한 내용은 [그래프와 세션](./graphs.md)에서 확인하세요). -`Tensor.eval`은 텐서와 같은 내용을 가지는 numpy 배열을 반환합니다. +`Tensor.eval`은 텐서와 같은 내용을 가지는 넘파이 배열을 반환합니다. 때때로 그 값이 이용할 수 없는 동적인 정보에 의존하기 때문에 컨텍스트(context)가 없는 `tf.Tensor`는 계산할 수 없는 경우가 있습니다. @@ -298,6 +298,6 @@ t = tf.Print(t, [t]) # 여기서 tf.Print에 의해 반환된 값을 사용할 result = t + 1 # 이제 결과를 계산할 때 `t` 값이 출력될 것입니다. ``` -`result`를 계산할 때 `result`이 관련된 모든 것이 계산될 것입니다. +`result`를 계산할 때 이와 관련된 모든 것이 계산될 것입니다. `result`는 `t`와 의존성이 있고, `t`를 계산하는 것이 그 입력(`t`의 이전 값)을 출력하는 부가 효과가 있기 때문에 `t`는 출력됩니다. From 278da5c93ad9ca7387d5e27b42debd8f86e42a1f Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Thu, 24 Oct 2019 15:54:48 +0900 Subject: [PATCH 10/13] KO: revise doc after @rickiepark's review --- site/ko/guide/tensor.md | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index 02e1cc29aea..7790cd76217 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -1,24 +1,24 @@ # 텐서플로 텐서 이름에서 알 수 있듯이, 텐서플로는 텐서를 포함한 계산을 정의하고 실행하는 프레임워크입니다. -*텐서*는 벡터와 행렬을 일반화한 것이고 고차원으로 확장 가능합니다. -내부적으로 텐서플로는 텐서를 기본 변수형의 n-차원 배열로 나타냅니다. +*텐서(tensor)*는 벡터와 행렬을 일반화한 것이고 고차원으로 확장 가능합니다. +내부적으로 텐서플로는 기본적으로 제공되는 자료형을 사용해 n-차원 배열로 나타냅니다. -텐서플로 프로그램을 작성할 때, 조작하고 전달하는 중요 객체는 `tf.Tensor` 입니다. -`tf.Tensor` 객체는 결과적으로는 값으로 변환될 수 있는 부분적으로 정의된 계산으로 표현됩니다. +텐서플로 프로그램을 작성할 때, `tf.Tensor`를 주로 조작하고 전달합니다. +`tf.Tensor` 객체는 부분적으로 정의된 연산으로 표현되고 이 것은 결국 값으로 변환됩니다. 텐서플로 프로그램은 `tf.Tensor` 객체 그래프를 만드는 것으로 먼저 시작하고, 각각의 텐서가 다른 텐서를 기반으로 어떤 식으로 계산될 수 있는지 구체화하고, 그 다음 그래프를 실행해서 원하는 결과를 얻게 됩니다. `tf.Tensor`는 다음과 같은 속성을 가지고 있습니다: - * 변수형 (예를 들어, `float32` 또는 `int32`, `string`) - * 형태 + * 자료형 (예를 들어, `float32` 또는 `int32`, `string`) + * 형태(shape) -텐서안의 각각 원소는 동일한 변수형이고 항상 그 변수형을 알 수 있습니다. +텐서안의 각각 원소는 동일한 자료형이고 항상 그 자료형을 알 수 있습니다. 형태(즉, 차원 수와 각 차원마다 길이)는 일부만 알 수 있습니다. -대부분 연산은 입력값 형태를 알 수 있다면 모든 정보를 알 수 있는 텐서를 만들지만, +대부분 연산은 입력값 형태를 알 수 있다면 형태가 완전하게 정의된 텐서를 만들지만, 일부 경우에서는 그래프를 실행한 이후에 텐서 형태를 알 수 있기도 합니다. 일부 특별한 텐서는 텐서플로 가이드문서의 다른 부분에서 다뤄질 것입니다. @@ -53,7 +53,7 @@ n | n-텐서 (알 수 있을겁니다(you get the idea)) ### 랭크 0 -다음은 랭크 0 변수 생성 예의 일부입니다: +다음은 랭크 0 변수 생성 예입니다: ```python mammal = tf.Variable("코끼리", tf.string) @@ -101,19 +101,19 @@ my_image = tf.zeros([10, 299, 299, 3]) # 배치 x 높이 x 너비 x 색상 ### `tf.Tensor` 객체 랭크 구하기 `tf.Tensor` 객체의 랭크를 알기 위해서는 `tf.rank` 메서드를 호출합니다. -예를 들어, 다음 메서드는 이전 섹션에서 정의된 `tf.Tensor`의 랭크를 프로그래밍 방식으로 알려줍니다. +예를 들어, 다음 메서드는 이전 섹션에서 정의된 `tf.Tensor`의 랭크를 알려줍니다. ```python r = tf.rank(my_image) -# 그래프가 실행된 후 r은 4라는 값을 가지게 됩니다. +# 이 코드가 실행된 후 r은 4라는 값을 가지게 됩니다. ``` ### `tf.Tensor` 일부분(slice) 참조하기 -`tf.Tensor`는 n-차원 배열로 구성된 셀이기 때문에, -`tf.Tensor`의 셀 하나에 접근하기 위해서는 n개의 인덱스가 필요합니다. +`tf.Tensor`는 n-차원 배열로 구성되어 있기 때문에 때문에, +`tf.Tensor`의 원소 하나에 접근하기 위해서는 n개의 인덱스가 필요합니다. -랭크 0 텐서(스칼라)인 경우 그것이 이미 하나의 숫자이기 때문에 인덱스가 필요없습니다. +랭크 0 텐서(스칼라)인 경우 이미 하나의 숫자이기 때문에 인덱스가 필요없습니다. 랭크 1 텐서(벡터)인 경우 숫자 하나에 접근하기 위해서는 인덱스 한 개를 전달해야 합니다: @@ -147,13 +147,13 @@ my_column_vector = my_matrix[:, 3] ## 형태 -텐서의 **형태**는 각 차원에 있는 원소 개수로 표현됩니다. +텐서의 **형태(shape)**는 각 차원에 있는 원소 개수로 표현됩니다. 텐서플로는 그래프 계산 과정에서 자동으로 텐서 형태를 추론합니다. 이렇게 추론된 형태는 랭크를 알고 있는 경우도 있고 그렇지 않는 경우도 있습니다. 만약에 랭크를 알고 있는 경우라도 각 차원의 원소 개수를 알고 있는 경우도 있고 그렇지 않는 경우도 있습니다. 텐서플로 문서에서 텐서 차원을 표현하기 위해서 3가지 용어를 사용합니다: 랭크, 형태, 차원. -다음 표는 각 용어가 다른 용어와 연관되어 있는지를 보여줍니다. +다음 표는 각 용어가 다른 용어와 어떻게 연관되어 있는지를 보여줍니다. 랭크 | 형태 | 차원 | 예제 --- | --- | --- | --- @@ -170,10 +170,10 @@ n | [D0, D1, ... Dn-1] | n-차원 | 형태가 [D0, D1, ... Dn-1]인 텐서. `tf.Tensor`의 형태를 알기 위한 2가지 방법이 있습니다. 그래프를 생성하는 동안 텐서의 형태를 알 수 있는 것은 종종 유용합니다. 형태는 `tf.Tensor`객체의 `shape` 속성으로 알 수 있습니다. -이 메서드는 `TensorShape`를 반환하고, 이러한 방식은 전체가 알려지지 않는 형태를 표현하는데 편리한 방법입니다 +이 메서드는 `TensorShape`를 반환하고, 이러한 방식은 완전하게 알지 못하는 형태를 표현하는데 편리한 방법입니다 (그래프를 생성할 때 모든 형태를 알 수 없기 때문에). -`tf.Tensor`를 얻는 것은 실행 시점에 형태를 알고 있는 다른 `tf.Tensor`로 표현할 수 있습니다. +실행 시점에 다른 `tf.Tensor` 객체의 완전한 형태를 표현하는 `tf.Tensor`를 얻을 수도 있습니다. 이것은 `tf.shape` 연산을 통해서 확인할 수 있습니다. 이를 통해, 입력 `tf.Tensor`의 동적인 형태에 연동된 다른 텐서를 생성함으로써 텐서 형태를 변경하는 그래프를 생성할 수 있습니다. @@ -199,8 +199,8 @@ rank_three_tensor = tf.ones([3, 4, 5]) matrix = tf.reshape(rank_three_tensor, [6, 10]) # 기존 내용을 6x10 행렬로 # 형태 변경 matrixB = tf.reshape(matrix, [3, -1]) # 기존 내용을 3x20 행렬로 형태 변경 - # -1은 차원 크기를 계산한 후에 - # 형태를 변경하라는 의미 + # -1은 차원 크기를 계산하여 + # 자동으로 결정하라는 의미 matrixAlt = tf.reshape(matrixB, [4, 3, -1]) # 기존 내용을 4x3x5 텐서로 # 형태 변경 @@ -211,25 +211,25 @@ matrixAlt = tf.reshape(matrixB, [4, 3, -1]) # 기존 내용을 4x3x5 텐서로 yet_another = tf.reshape(matrixAlt, [13, 2, -1]) # 에러! ``` -## 변수형 +## 자료형 -차원뿐만 아니라, 텐서는 변수형도 가지고 있습니다. -전체 변수형을 확인하려면 `tf.DType`를 참고하세요. +차원뿐만 아니라, 텐서는 자료형도 가지고 있습니다. +전체 자료형을 확인하려면 `tf.DType`를 참고하세요. -`tf.Tensor`가 한 개이상의 변수형을 가지는 것은 불가능합니다. +`tf.Tensor`가 한 개이상의 자료형을 가지는 것은 불가능합니다. 임의의 데이터 구조를 직렬화한 `string`를 저장한 `tf.Tensor`는 예외입니다. -`tf.cast`를 이용해서 `tf.Tensor`의 변수형을 다른 것으로 변경하는 것은 가능합니다: +`tf.cast`를 이용해서 `tf.Tensor`의 자료형을 다른 것으로 변경하는 것은 가능합니다: ``` python # 정수형 텐서를 실수형으로 변환. float_tensor = tf.cast(tf.constant([1, 2, 3]), dtype=tf.float32) ``` -`tf.Tensor`의 변수형을 확인하기 위해서는 `Tensor.dtype` 속성을 활용하세요. +`tf.Tensor`의 자료형을 확인하기 위해서는 `Tensor.dtype` 속성을 활용하세요. -파이썬 객체를 이용해서 `tf.Tensor`를 생성할 때 변수형을 선택적으로 명시할 수 있습니다. -그렇지 않으면 텐서플로가 데이터 표현에 적합한 변수형을 선택합니다. +파이썬 객체를 이용해서 `tf.Tensor`를 생성할 때 자료형을 선택적으로 명시할 수 있습니다. +그렇지 않으면 텐서플로가 데이터 표현에 적합한 자료형을 선택합니다. 텐서플로는 파이썬 정수를 `tf.int32`로 변환하고 파이썬 실수는 `tf.float32`으로 변환합니다. 그외에 동일한 규칙을 넘파이(numpy)를 배열로 변경할 때 사용합니다. From 7fb88cad32f6cfc075eeaf5dda9e458b82cbd624 Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Fri, 25 Oct 2019 13:27:13 +0900 Subject: [PATCH 11/13] KO: revise doc after @rickiepark's comments --- site/ko/guide/tensor.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index 7790cd76217..55dd47582ae 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -5,7 +5,7 @@ 내부적으로 텐서플로는 기본적으로 제공되는 자료형을 사용해 n-차원 배열로 나타냅니다. 텐서플로 프로그램을 작성할 때, `tf.Tensor`를 주로 조작하고 전달합니다. -`tf.Tensor` 객체는 부분적으로 정의된 연산으로 표현되고 이 것은 결국 값으로 변환됩니다. +`tf.Tensor` 객체는 부분적으로 정의된 연산으로 표현되고 이것은 결국 값으로 변환됩니다. 텐서플로 프로그램은 `tf.Tensor` 객체 그래프를 만드는 것으로 먼저 시작하고, 각각의 텐서가 다른 텐서를 기반으로 어떤 식으로 계산될 수 있는지 구체화하고, 그 다음 그래프를 실행해서 원하는 결과를 얻게 됩니다. @@ -108,7 +108,7 @@ r = tf.rank(my_image) # 이 코드가 실행된 후 r은 4라는 값을 가지게 됩니다. ``` -### `tf.Tensor` 일부분(slice) 참조하기 +### `tf.Tensor` 원소 참조하기 `tf.Tensor`는 n-차원 배열로 구성되어 있기 때문에 때문에, `tf.Tensor`의 원소 하나에 접근하기 위해서는 n개의 인덱스가 필요합니다. From ed407b07a2b8516fd625ac18a3088a1106ba65e8 Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Mon, 28 Oct 2019 09:54:47 +0900 Subject: [PATCH 12/13] KO: revise doc after @rickiepark's second review --- site/ko/guide/tensor.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index 55dd47582ae..84a67a234f5 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -235,8 +235,8 @@ float_tensor = tf.cast(tf.constant([1, 2, 3]), dtype=tf.float32) ## 텐서 계산하기(evaluate) -일단 계산 그래프를 만들었다면, 특정 `tf.Tensor`를 생성하고 그것에 지정된 값을 가져오는 계산을 실행할 수 있습니다. -이것은 대부분의 텐서플로가 작업하는데 필요할 뿐 아니라 디버깅에 종종 유용합니다. +일단 계산 그래프를 만들었다면, 특정 `tf.Tensor`를 생성하거나 텐서에 할당된 값을 가져오는 계산을 실행할 수 있습니다. +이것은 텐서플로 작업의 많은 부분에서 필요할 뿐 아니라 디버깅에 종종 유용합니다. 텐서를 계산하는 가장 간단한 방법은 `Tensor.eval` 메서드를 사용하는 것입니다. 예를 들어: @@ -251,9 +251,9 @@ print(tensor.eval()) `Tensor.eval`은 텐서와 같은 내용을 가지는 넘파이 배열을 반환합니다. -때때로 그 값이 이용할 수 없는 동적인 정보에 의존하기 때문에 +때때로 현재 사용할 수 없는 동적인 정보에 의존하기 때문에 컨텍스트(context)가 없는 `tf.Tensor`는 계산할 수 없는 경우가 있습니다. -예를 들어, `placeholder`인 텐서는 그 `placeholder`에 해당하는 값이 제공되지 않으면 계산할 수 없습니다. +예를 들어, `placeholder`에 의존하는 텐서는 그 `placeholder`에 해당하는 값이 제공되지 않으면 계산할 수 없습니다. ``` python p = tf.placeholder(tf.float32) @@ -268,7 +268,7 @@ t.eval(feed_dict={p:2.0}) # 플레이스홀더에 해당하는 값을 제공받 다른 모델 구조는 `tf.Tensor`를 계산하는 것을 복잡하게 만들 수 있습니다. 텐서플로는 함수안이나 제어 흐름안에 정의된 `tf.Tensor`를 직접 계산할 수 없습니다. 만약에 `tf.Tensor`가 큐(queue)에 있는 값을 사용한다면, -무언가가 큐에 들어간 후에 만 `tf.Tensor` 계산을 할 수 있습니다; 그렇지 않으면 계산은 중단될 것입니다. +무언가가 큐에 들어간 후에 만 `tf.Tensor` 계산을 할 수 있습니다; 그렇지 않으면 계산은 멈출(hang) 것입니다. 큐와 같이 작업할 때, `tf.Tensor`를 계산하기 전 `tf.train.start_queue_runners`를 호출하세요. ## 텐서 출력하기 From dfca1e747f8667f00b28d308781f5e96140a0c15 Mon Sep 17 00:00:00 2001 From: Woo-Cheol Kim Date: Tue, 29 Oct 2019 11:01:30 +0900 Subject: [PATCH 13/13] KO: remove section 'Print a tensor' --- site/ko/guide/tensor.md | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/site/ko/guide/tensor.md b/site/ko/guide/tensor.md index 84a67a234f5..f991916aa29 100644 --- a/site/ko/guide/tensor.md +++ b/site/ko/guide/tensor.md @@ -270,34 +270,3 @@ t.eval(feed_dict={p:2.0}) # 플레이스홀더에 해당하는 값을 제공받 만약에 `tf.Tensor`가 큐(queue)에 있는 값을 사용한다면, 무언가가 큐에 들어간 후에 만 `tf.Tensor` 계산을 할 수 있습니다; 그렇지 않으면 계산은 멈출(hang) 것입니다. 큐와 같이 작업할 때, `tf.Tensor`를 계산하기 전 `tf.train.start_queue_runners`를 호출하세요. - -## 텐서 출력하기 - -디버깅을 위해서 `tf.Tensor` 값을 출력하고 싶을 것입니다. -고급 디버깅에 대해 [tfdbg](../guide/debugger.md)에서 가이드를 제공하지만, -텐서플로는 `tf.Tensor`값을 직접 출력할 수 있는 연산자를 가지고 있습니다. - -`tf.Tensor`를 출력할 때 다음과 같은 패턴을 쓰고자 하는 경우는 거의 없습니다: - -``` python -t = <> -print(t) # 이것은 그래프가 생성되어질 때 기호화된 텐서(symbolic tensor)를 출력할 것입니다. - # 이 텐서는 이 컨텍스트(context)안에서 값을 가지고 있지 않습니다. -``` - -이 코드는 `tf.Tensor`의 값이 아닌 객체(지연 계산으로 표현)를 출력합니다. -실제로 텐서플로는 두번째 인수로 전달된 `tf.Tensor` 집합을 출력하는 동안 -변경되지 않는 첫번째 텐서 인수를 반환하는 `tf.Print` 연산을 제공합니다. - -`tf.Print`을 제대로 사용하기 위해서는 반환된 값을 사용해야 합니다. 아래 예를 보면 - -``` python -t = <> -tf.Print(t, [t]) # 어떤 일도 하지 않습니다 -t = tf.Print(t, [t]) # 여기서 tf.Print에 의해 반환된 값을 사용할 수 있습니다. -result = t + 1 # 이제 결과를 계산할 때 `t` 값이 출력될 것입니다. -``` - -`result`를 계산할 때 이와 관련된 모든 것이 계산될 것입니다. -`result`는 `t`와 의존성이 있고, `t`를 계산하는 것이 그 입력(`t`의 이전 값)을 출력하는 부가 효과가 있기 때문에 `t`는 출력됩니다. -